Skip to content

Commit

Permalink
Add exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
kj4ezj committed Feb 27, 2024
1 parent fe639f6 commit 7f884e3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions entry.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
unset RETRY_INTERVAL
while true; do
RUN_TIME="$(date '+%s')"
# shellcheck disable=SC2086
Expand All @@ -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

0 comments on commit 7f884e3

Please sign in to comment.