Repository navigation
Keep Retry intervals given as a one-shot iterator - #2552
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Preserve and validate retry intervals rq/job.py, tests/test_retry.py |
Retry.__init__ converts the interval iterable to a list before checking for negative values. Tests verify that iterator values are retained, negative values raise ValueError, and a failing job is scheduled by a burst worker. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: selwin
Merge Risk: 
Minimal · up to 91b7b
-
No actionable merge-blocking risk remains.
Pre-merge checks: 
5
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2552 +/- ##
==========================================
+ Coverage 93.61% 95.22% +1.60%
==========================================
Files 28 43 +15
Lines 3760 5612 +1852
==========================================
+ Hits 3520 5344 +1824
- Misses 240 268 +28 ☔ View full report in Codecov by Harness. |
Problem
Retry(interval=...)accepts any iterable, butRetry.__init__()checks the values for negatives by looping overintervaland then builds the list withlist(interval). A generator,map()oriter()is used up by the check, soRetry.intervalsends up as[]with no error.With
retry=Retry(max=3, interval=<generator>)passed toenqueue(), the first time the job raises,Job.get_retry_interval()indexes the empty list and raisesIndexErrorinside the worker's failure handling. The worker logs "found an unhandled exception, quitting..." and exits, and the job staysstarted. When it is later picked up as abandoned,StartedJobRegistry.cleanup()callsjob.retry()and hits the sameIndexError, so the next worker quits during its startup maintenance as well.A job that returns
Retry(interval=<generator>)doesn't crash anything, butRetry.get_interval()returns 0 for an empty list, so it is requeued at once with no backoff.Reproduction
Real Redis 8.10.2, rq master (aacfa5b) and rq 2.12.0 from PyPI, default
Worker, nothing mocked:After the first job's entry in the started registry expired (about 90 seconds here), a new
Workerquit the same way fromclean_registries(). With a list,Retry(max=3, interval=[10, 20, 40]), the job is scheduled for retry as expected.Change
Retry.__init__()now builds the list first and checks that, which is whatRepeat.__init__()already does. Lists, tuples and ranges behave as before, and negative values are still rejected.Verification
test_retry_interval_from_iteratorfails on master and passes with the fix, 10 runs each way. It also checks that a negative value in an iterator is still rejected and that a failing job is scheduled for retry.tests/test_retry.py: 18 passed before, 19 after. Full suite: 768 passed, 24 skipped on master; 769 passed, 24 skipped with the fix.ruff checkandruff format --checkon the changed files are clean.Summary by CodeRabbit