-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbwait
More file actions
executable file
·39 lines (31 loc) · 1.03 KB
/
bwait
File metadata and controls
executable file
·39 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
(( DEBUG )) && set -x
[[ $1 == '-h' ]] && {
cat <<EOF
bwait <job-name>
wait for the specified job to finish (enter condition of complete or failed.
See repository README.md for more documentation and examples.
EOF
exit 0
}
typeset -r JOB=$1
declare -i VERBOSE=${VERBOSE:-0}
typeset -i -r MAX_SEC="${MAX_SEC:-$(( 60 * 15 ))}"
typeset -i -r JOB_WAIT_TMOUT="${JOB_WAIT_TMOUT:-$(( MAX_SEC * 4 ))}"
typeset OUT=/dev/null
typeset -i -r JOB_DELETE="${JOB_DELETE:-1}"
(( VERBOSE )) && OUT=/dev/stderr
oc wait --for=condition=complete --timeout=${JOB_WAIT_TMOUT}s jobs/$JOB >$OUT 2>&1 & complete_pid=$!
oc wait --for=condition=failed --timeout=${JOB_WAIT_TMOUT}s jobs/$JOB >$OUT 2>&1 && exit -1 & failed_pid=$!
echo "Waiting $JOB for condition: complete or failed" > $OUT
wait -n $complete_pid $failed_pid
rc=$?
if (( $rc == 0 )); then
echo "$JOB: Completed" >$OUT
else
echo "*** ERROR: $JOB FAILED!!!! *****"
fi
oc logs jobs/$JOB
(( JOB_DELETE )) && {
oc delete jobs/$JOB >$OUT 2>&1
}