Created
May 22, 2014 00:25
-
-
Save takekazuomi/e608c80b0fddea19fc79 to your computer and use it in GitHub Desktop.
retry wrapper script for azure xplat tools
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
#!/bin/bash -u | |
declare -i retries=${1:?"no retry count"} | |
shift | |
declare -i time_wait=${1:?"no time out sec"} | |
shift | |
declare result_code=0 | |
for i in $(seq 0 $retries); do | |
/usr/bin/azure "$@" | |
result_code=$? | |
if [ $result_code -ne 0 ]; then | |
# if [ -f azure.err ]; then | |
if cat azure.err 1>&2 ; then | |
mv azure.err azure.err.old | |
status_code=`awk '/, statusCode:/ {print $6} /^ statusCode:/ {print $2}' azure.err` | |
if [[ "$status_code" =~ (307|404) ]]; then | |
# not retryable error | |
exit $result_code | |
fi | |
fi | |
if [ $i -eq 0 ]; then | |
echo "error start retry. " 1>&2 | |
else | |
echo -n "." 1>&2 | |
fi | |
test $i -ne $retries && sleep $time_wait | |
else | |
exit $result_code | |
fi | |
done | |
test $retries -ne 0 && echo "timed out abort.." 1>&2 | |
exit $result_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment