From 328682160e3e7b35b261b38b21a016719db0be29 Mon Sep 17 00:00:00 2001 From: tcely Date: Sat, 14 Jun 2025 14:58:53 -0400 Subject: [PATCH] Better handling of large retries --- tubesync/common/huey.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tubesync/common/huey.py b/tubesync/common/huey.py index 4fc44c84..a4c7866a 100644 --- a/tubesync/common/huey.py +++ b/tubesync/common/huey.py @@ -74,10 +74,13 @@ def exponential_backoff(task_func=None, /, *args, **kwargs): try: return fn(*a, **kwa) except Exception as exc: - attempt = 1 - while task.retry_delay <= backoff(attempt): - attempt += 1 - task.retry_delay = backoff(attempt) + for attempt in range(1, 1_001): + if backoff(attempt) > task.retry_delay: + task.retry_delay = backoff(attempt) + break + # insanity, but handle it anyway + if 1_000 == attempt: + task.retry_delay = backoff(attempt) raise exc kwargs.update(dict( context=True,