Skip to content

Commit

Permalink
retry: Optimize for happy-path with until-loop
Browse files Browse the repository at this point in the history
This simplifies and optimizes the retry command to only do the check for
the number of left retries when actually needed.
  • Loading branch information
okurz committed Mar 23, 2022
1 parent afbe4a4 commit aacb70e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions retry
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
RETRIES="${RETRIES:-3}"
SLEEP="${SLEEP:-3}"

while [ "$RETRIES" -ge 0 ] ; do
# shellcheck disable=SC2048
# shellcheck disable=SC2048
until $*; do
[ "$RETRIES" -ge 0 ] || break
$* && break
echo "Retrying up to $RETRIES more times after sleeping ${SLEEP}s …"
RETRIES=$((RETRIES-1))
Expand Down

0 comments on commit aacb70e

Please sign in to comment.