Skip to content

Commit

Permalink
take 2 at wait logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Sep 27, 2024
1 parent 277c57a commit 0c924c1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions resources/launch_scripts/local-scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ echo "Dumping pidmap:"
for pid in "${!pidmap[@]}"; do
echo "PID: $pid, Identifier: ${pidmap[$pid]}"
done
while [ ${#pidmap[@]} -gt 0 ]; do
sleep 5
# Wait for the first finished process
if ! finished_pid=$(wait -n); then
echo "$finished_pid"
echo "ERROR: component '${pidmap[$finished_pid]}' failed"

# Wait for all background processes to complete, looping in reverse order
pids=("${!pid_map[@]}") # get keys
reversed_pids=($(for pid in "${pids[@]}"; do echo $pid; done | tac)) # reverse key order
for pid in "${reversed_pids[@]}"; do
set -x
wait $pid
set +x
exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "ERROR: component '${pidmap[$pid]}' failed with status $exit_status"
sleep 5 # May need to wait for output files to be written
kill "${!pidmap[@]}" 2>/dev/null # kill all
exit 1
else
echo "$finished_pid"
echo "SUCCESS: component '${pidmap[$finished_pid]}' completed successfully"
unset pidmap["$finished_pid"] # remove the finished PID from the associative array
echo "SUCCESS: component '${pidmap[$pid]}' completed successfully"
fi
done

0 comments on commit 0c924c1

Please sign in to comment.