-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(retry): wrap everything that depends on external dependencies on…
… a retry with backoff
- Loading branch information
Showing
6 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Retries a command a configurable number of times with backoff. | ||
# | ||
# The retry count is given by ATTEMPTS (default 5), the initial backoff | ||
# timeout is given by TIMEOUT in seconds (default 1.) | ||
# | ||
# Successive backoffs double the timeout. | ||
function with_backoff { | ||
local max_attempts=${ATTEMPTS-5} | ||
local timeout=${TIMEOUT-5} | ||
local attempt=1 | ||
local exitCode=0 | ||
|
||
while (( $attempt < $max_attempts )) | ||
do | ||
if "$@" | ||
then | ||
return 0 | ||
else | ||
exitCode=$? | ||
fi | ||
|
||
echo "Failure! Retrying in $timeout.." 1>&2 | ||
sleep $timeout | ||
attempt=$(( attempt + 1 )) | ||
timeout=$(( timeout * 2 )) | ||
done | ||
|
||
if [[ $exitCode != 0 ]] | ||
then | ||
echo "You've failed me for the last time! ($@)" 1>&2 | ||
fi | ||
|
||
return $exitCode | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters