Skip to content

Reschedule increases attempt value #36

Description

@srgnk

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions