From 7f884e3a4dc272cab10e7d2a44c494b2d5c6e188 Mon Sep 17 00:00:00 2001 From: Zach Butler Date: Mon, 26 Feb 2024 19:29:12 -0500 Subject: [PATCH] Add exponential backoff --- entry.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/entry.sh b/entry.sh index efd1d62..a565c86 100755 --- a/entry.sh +++ b/entry.sh @@ -1,4 +1,5 @@ #!/bin/sh +unset RETRY_INTERVAL while true; do RUN_TIME="$(date '+%s')" # shellcheck disable=SC2086 @@ -8,10 +9,17 @@ while true; do MOD_TIME="$(date -r "/data/$XMLTV_FILENAME" '+%s')" if test "$MOD_TIME" -gt "$RUN_TIME"; then echo "Will run again in $SLEEPTIME seconds." + unset RETRY_INTERVAL sleep "$SLEEPTIME" + elif [ -z "$RETRY_INTERVAL" ]; then + echo 'This run did not complete successfully, trying again...' + RETRY_INTERVAL='30' else - echo 'This run did not complete successfully.' - echo 'Pausing for 30 seconds and trying again...' - sleep 30 + echo "This run did not complete successfully, trying again in $RETRY_INTERVAL seconds..." + sleep "$RETRY_INTERVAL" + RETRY_INTERVAL="$(( RETRY_INTERVAL * 2 ))" + if test "$RETRY_INTERVAL" -gt "$SLEEPTIME"; then + RETRY_INTERVAL='30' + fi fi done