mirror of
https://github.com/balena-io/open-balena.git
synced 2025-02-01 08:48:26 +00:00
3be25c1563
* orchestrate openBalena on ephemeral device(s) in AWS with GHA workflow * uses another WIP project to create a virtual test device * adds placeholder openBalena test suite Change-type: major
33 lines
660 B
Plaintext
33 lines
660 B
Plaintext
# https://coderwall.com/p/--eiqg/exponential-backoff-in-bash
|
|
function with_backoff() {
|
|
local max_attempts=${ATTEMPTS-5}
|
|
local timeout=${TIMEOUT-1}
|
|
local attempt=0
|
|
local exitCode=0
|
|
|
|
set +e
|
|
while [[ $attempt < $max_attempts ]]
|
|
do
|
|
"$@"
|
|
exitCode=$?
|
|
|
|
if [[ $exitCode == 0 ]]
|
|
then
|
|
break
|
|
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
|
|
|
|
set -e
|
|
return $exitCode
|
|
}
|