Skip to content

Commit

Permalink
Run command in function with explicit check for return code
Browse files Browse the repository at this point in the history
This change fixes false negative if cmd passed on last retry.
  • Loading branch information
mimi1vx committed Nov 24, 2023
1 parent fbcdfe5 commit bf497ce
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions retry
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ done
retries="${retries:-3}"
sleep="${sleep:-3}"

ret=0
until "$@"; do
while true; do
set +e
"$@"
ret=$?
set -e
[ $ret -eq 0 ] && exit 0
[ "$retries" -gt 0 ] || break
echo "Retrying up to $retries more times after sleeping ${sleep}s …" >&2
retries=$((retries-1))
sleep "$sleep"
[ -n "$exponential" ] && sleep=$((sleep*exponential))
done

[ $retries -gt 0 ] || [ $ret -eq 0 ]
[ $retries -gt 0 ]

0 comments on commit bf497ce

Please sign in to comment.