Input
store.enqueue('send_email', {'to': 'a@x.com'}); processor.register('send_email', lambda p: None); processor.process_next(now=0)Output
Returns True. Job's state == 'succeeded', attempts == 1.
You're building the worker that drains a job queue in a production backend. Jobs sometimes succeed, sometimes fail transiently (a flaky API, a timeout), and sometimes fail permanently (bad payload, expired credential)....
queue_store.pyEditable starterprocessor.pyEditable starterstore.enqueue('send_email', {'to': 'a@x.com'}); processor.register('send_email', lambda p: None); processor.process_next(now=0)Returns True. Job's state == 'succeeded', attempts == 1.
Handler raises TransientError on first call, succeeds on second. max_retries=3, retry_delay_seconds=5. process_next(now=0) → fails, schedules retry at t=5 process_next(now=4) → returns False (not yet runnable) process_next(now=5) → succeeds
Final state == 'succeeded', attempts == 2.
How would you add exponential backoff so retry #2 waits longer than retry #1? Where would the formula live so it's testable without time-based flakes?