This might not be the issue of the code at all, but reschedule method confused me a bit.
The following snippet of code would increase the job's attempt value by 1:
with rq.dequeue("tasks") as job:
job.reschedule()
While the reschedule's docstring explicitly says
the current attempt won't count towards the maximum number of retries.
Turns out that it's not the reschedule that bumps up the attempt value but context manager dequeue.
That is, the following code would leave the attempt intact:
job = rq.jobs("tasks")[0]
job.reschedule()
From the user's perspective these 2 ways of rescheduling jobs don't differ much, but they work differently.
I am also assuming that dequeue is the recommended way of picking up jobs but this option would almost always add 1 to the attempt value which contradicts the example in the README file:
The reschedule() method is used to reprocess the job at a later time. The job will remain in the queue with a new scheduled execution time, and the current attempt won't count towards the maximum number of retries.
This method should only be called inside the dequeue() context manager.
with rq.dequeue("my-queue") as job:
# Check if we have everything ready to process the job, and if not,
# reschedule the job to run 10 minutes from now
if not is_everything_ready_to_process(job.payload):
job.reschedule(delay=timedelta(minutes=10))
else:
# Otherwise, process the job
do_work(job.payload)
This might not be the issue of the code at all, but
reschedulemethod confused me a bit.The following snippet of code would increase the job's
attemptvalue by 1:While the reschedule's docstring explicitly says
Turns out that it's not the
reschedulethat bumps up theattemptvalue but context managerdequeue.That is, the following code would leave the
attemptintact:From the user's perspective these 2 ways of rescheduling jobs don't differ much, but they work differently.
I am also assuming that
dequeueis the recommended way of picking up jobs but this option would almost always add 1 to theattemptvalue which contradicts the example in theREADMEfile: