Skip to content

Instantly share code, notes, and snippets.

View drjasonharrison-vp-eio's full-sized avatar

Jason Harrison drjasonharrison-vp-eio

View GitHub Profile
@drjasonharrison-vp-eio
drjasonharrison-vp-eio / expbackoff.sh
Created March 29, 2019 00:21 — forked from nathforge/expbackoff.sh
Exponential backoff in Bash
expbackoff() {
# Exponential backoff: retries a command upon failure, scaling up the delay between retries.
# Example: "expbackoff my_command --with --some --args --maybe"
local MAX_RETRIES=${EXPBACKOFF_MAX_RETRIES:-8} # Max number of retries
local BASE=${EXPBACKOFF_BASE:-1} # Base value for backoff calculation
local MAX=${EXPBACKOFF_MAX:-300} # Max value for backoff calculation
local FAILURES=0
while ! "$@"; do
FAILURES=$(( $FAILURES + 1 ))
if (( $FAILURES > $MAX_RETRIES )); then