feat: Support task backoff#81
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 94.17% 94.42% +0.25%
==========================================
Files 74 74
Lines 2147 2208 +61
==========================================
+ Hits 2022 2085 +63
+ Misses 125 123 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
matthewelwell
left a comment
There was a problem hiding this comment.
My general concern with this is that we could end up with a task infinitely failing and being rescheduled, right? Also, I don't see any logic here that 'nullifies' the original retry logic that will still retry the task as soon as possible, to a maximum of 3 times. Shouldn't we also intercept that logic somehow?
| assert registered_task.task_handler, ( | ||
| "Attempt to back off a recurring task (currently not supported)" | ||
| ) |
There was a problem hiding this comment.
Why not use registered_task.task_type here?
There was a problem hiding this comment.
The assertion also reassures Mypy that the task_handler attribute is not None.
This is a valid concern. We could do one of the following to address it:
Note that both of the options will cap the backoff attempts at the currently hard-coded value of 3 attempts.
Good catch, done in b905d54 — but that will need to be reverted should we choose the option (2) above. |
|
Implemented option 2 in 9de8df5, which also resulted in a leaner overall diff 👍 |
This PR adds support for task backoff via raising a
TaskBackoffError.The task runner now reschedules a task if the above exception class is raised inside a regular (non-recurring) task. The exception class supports a
delay_untilargument to specify which datetime the next task invocation should be scheduled for. If not specified,settings.TASK_BACKOFF_DEFAULT_DELAY_SECONDSwill be used.