open-balena/functions
ab77 3be25c1563
(WIP) openBalena on balenaOS
* 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
2022-03-22 08:12:39 -07:00

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
}