Last active
August 8, 2023 12:56
-
-
Save Albertoimpl/d9cce5eddf1e3670b7d5a740788755e5 to your computer and use it in GitHub Desktop.
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 | |
set -uo pipefail | |
function check_s3_status() { | |
S3_BUCKET_STATUS=$(curl -I https://my-buckets.s3.amazonaws.com | head -n 1) | |
[[ ${S3_BUCKET_STATUS} == *"HTTP/1.1 200 OK"* ]] && echo "OK with code: ${S3_BUCKET_STATUS}" && return 0 | |
echo "Failed with code: ${S3_BUCKET_STATUS}" | |
return 1 | |
} | |
function with_backoff { | |
local MAX_RETRIES=6 | |
local DELAY=0 | |
local RETRY_COUNT=0 | |
local EXIT_CODE=0 | |
while [[ "${MAX_RETRIES}" -gt "${RETRY_COUNT}" ]] | |
do | |
"$@" | |
EXIT_CODE=$? | |
if [[ ${EXIT_CODE} == 0 ]] | |
then | |
break | |
fi | |
echo "Retrying in ${DELAY}" | |
sleep ${DELAY} | |
RETRY_COUNT=$(( ${RETRY_COUNT} + 1 )) | |
DELAY=$(( (2**${RETRY_COUNT}) * 5 )) | |
done | |
return ${EXIT_CODE} | |
} | |
with_backoff check_s3_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment