Skip to content

Instantly share code, notes, and snippets.

@dathanb
Created August 12, 2021 21:35
Show Gist options
  • Save dathanb/6d0f6eb083ee54b5e512763d2fa4eeb1 to your computer and use it in GitHub Desktop.
Save dathanb/6d0f6eb083ee54b5e512763d2fa4eeb1 to your computer and use it in GitHub Desktop.
Retryable curl
# Try hard to make idempotent calls to services that are a little flaky
function retryableCurl() {
for i in `seq 1 5`; do
code="$(curl -s -o /dev/null -w "%{http_code}" "$@")"
if [[ $? -eq 0 && code -lt 300 && code -ge 200 ]]; then
return
fi
done
printf "Failed to curl with arguments $*\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment