Skip to content

Commit 969bb21

Browse files
committed
update wait-for-job-finish.sh
1 parent 23a3f50 commit 969bb21

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

.circleci/wait-for-job-finish.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
#!/usr/bin/env bash
22

3-
# Exit script when any executed command return non-zero code.
4-
set -e
5-
63
# Exit script if you try to use an uninitialized variable.
74
set -o nounset
85

96
# Use the error status of the first failure, rather than that of the last item in a pipeline.
107
set -o pipefail
118

12-
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
13-
9+
trap 's=$?; echo -e >&2 "\nError in $0:\nat line "$LINENO": $BASH_COMMAND"; exit $s' ERR
1410

11+
date
1512
counter=0
1613

1714
# Wait up to 25 minutes for job to finish. A job can run on multiple nodes: parallelism > 1
1815
while [ "$counter" -le 1500 ]; do
19-
# Find number of nodes in running
20-
job_detail=$(curl -s "https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM")
21-
job_running_nodes_count=$(echo "$job_detail" | jq -r '.parallel_runs[] | select(.status == "running") | select(.index != '"$CIRCLE_NODE_INDEX"')' | grep -c "running")
22-
23-
if [ "$job_running_nodes_count" -eq 0 ]; then
24-
exit 0
16+
# Find number of nodes in running or queued
17+
build_detail=$(curl -s "https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM")
18+
19+
running_vm=$(echo "$build_detail" | jq -r --arg INDX "$CIRCLE_NODE_INDEX" '.parallel_runs[] | select(.status=="running") | select(.index|tostring!=$INDX)')
20+
count=$(echo "$running_vm" | grep -c -e "running" || test $? = 1;)
21+
if [ "$count" -eq 0 ]; then
22+
echo "Parallel runs have finished. Exiting wait-for-job-finish script."
23+
exit 0
2524
fi
2625

26+
echo "Waiting for parallel runs to finish..."
2727
sleep 10
2828
counter=$(($counter + 10))
2929
done
3030

3131
echo "Waited total $counter seconds"
32-
date
3332

3433
# Something is wrong. Log response for error troubleshooting
3534
curl -s "https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM" | jq -r '.'

0 commit comments

Comments
 (0)