Files
proxmox/scripts/utils/retry_with_backoff.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

37 lines
1.2 KiB
Bash

#!/usr/bin/env bash
# Retry with exponential backoff - Recommendation from docs/10-best-practices/RECOMMENDATIONS_AND_SUGGESTIONS.md
# Usage: source this file, then: retry_with_backoff 3 2 some_command [args...]
# $1 = max_attempts, $2 = initial_delay_seconds, rest = command and args
retry_with_backoff() {
local max_attempts="${1:?Usage: retry_with_backoff MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]}"
local delay="${2:?Usage: retry_with_backoff MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]}"
shift 2
local attempt=1
while [ "$attempt" -le "$max_attempts" ]; do
if "$@"; then
return 0
fi
if [ "$attempt" -lt "$max_attempts" ]; then
echo "[WARN] Attempt $attempt failed, retrying in ${delay}s..." >&2
sleep "$delay"
delay=$((delay * 2))
fi
attempt=$((attempt + 1))
done
echo "[ERROR] Failed after $max_attempts attempts" >&2
return 1
}
# Allow script to be sourced or run (run = execute first non-option args as command)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [[ $# -ge 3 ]]; then
retry_with_backoff "$@"
else
echo "Usage: $0 MAX_ATTEMPTS INITIAL_DELAY COMMAND [ARGS...]"
echo "Example: $0 3 2 curl -s -o /dev/null -w '%{http_code}' https://example.com"
exit 2
fi
fi