Last active
October 22, 2020 07:58
-
-
Save fridim/9fbc20900d4b4569ccaf78f1b6f2b464 to your computer and use it in GitHub Desktop.
Retry wrapper in Bash
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
do_cmd_timeout_retry() { | |
local RETRIES=0 | |
local MAX_RETRIES=10 | |
local TIMEOUT=60 | |
local DELAY=60 | |
while [[ $RETRIES -le $MAX_RETRIES ]]; do | |
timeout ${TIMEOUT} "$@" | |
local ret=$? | |
[[ $ret == 0 ]] && break | |
echo "command '$@' failed, retrying in $DELAY" | |
RETRIES=$((RETRIES + 1)) | |
sleep ${DELAY} | |
done | |
} | |
do_cmd_retry_timeout git pull ... # if github temporary down, it'll retry for ~10 min |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment