refactor: unify grouped execution order

This commit is contained in:
lingkai5wu committed 2026-10-10 17:17:17 +08:00
1 parent 3da799a526
commit 48ddc3e728
1 file changed
+36 -21
+36 -21
View File
@@ -335,12 +335,30 @@ run_group() {
fi fi
case "$action" in case "$action" in
up | start) working_result="Starting"; success_result="Started" ;; up | start)
restart) working_result="Restarting"; success_result="Restarted" ;; working_result="Starting"
stop) working_result="Stopping"; success_result="Stopped" ;; success_result="Started"
down) working_result="Removing"; success_result="Removed" ;; ;;
pull) working_result="Pulling"; success_result="Pulled" ;; restart)
update) working_result="Updating"; success_result="Updated" ;; working_result="Restarting"
success_result="Restarted"
;;
stop)
working_result="Stopping"
success_result="Stopped"
;;
down)
working_result="Removing"
success_result="Removed"
;;
pull)
working_result="Pulling"
success_result="Pulled"
;;
update)
working_result="Updating"
success_result="Updated"
;;
esac esac
while :; do while :; do
@@ -438,6 +456,7 @@ collect_skipped_groups() {
run_all_grouped() { run_all_grouped() {
local action="$1" local action="$1"
local direction="forward" local direction="forward"
local start=0 end="${#GROUP_NAMES[@]}" step=1
local i local i
RUN_SUCCESS=0 RUN_SUCCESS=0
@@ -448,23 +467,19 @@ run_all_grouped() {
if [[ "$action" == "stop" || "$action" == "down" ]]; then if [[ "$action" == "stop" || "$action" == "down" ]]; then
direction="reverse" direction="reverse"
for ((i = ${#GROUP_NAMES[@]} - 1; i >= 0; i--)); do start=$((end - 1))
if ! run_group "$i" "$action"; then end=-1
collect_skipped_groups "$i" "$direction" step=-1
print_run_summary
return 1
fi
done
else
for ((i = 0; i < ${#GROUP_NAMES[@]}; i++)); do
if ! run_group "$i" "$action"; then
collect_skipped_groups "$i" "$direction"
print_run_summary
return 1
fi
done
fi fi
for ((i = start; i != end; i += step)); do
if ! run_group "$i" "$action"; then
collect_skipped_groups "$i" "$direction"
print_run_summary
return 1
fi
done
print_run_summary print_run_summary
} }