Skip to main content

RQ Retry and Scheduler

Project description

Build Status Coverage Status

RQ Retry Scheduler

RQ Retry Scheduler extends the RQ worker class to provide functionality to enqueue jobs based on time.

Additionally, it provides a worker that will automatically retry failed jobs using a backoff scheme.

Usage

Queues

The rq_retry_scheduler.Queue class can be used as a drop in replacement for rq.Queue. It provides two additional enqueuing methods:

  • enqueue_at - Enqueue the job at the specified time. The time should be a datetime.datetime object with the UTC timezone.

  • enqueue_in - Enqueue the job after the specified amount of time. The time should be a datetime.timedelta object.

Additionally, two other methods are available enqueue_job_at and enqueue_job_in which work like the above methods but take a rq.Job object as the paramter.

Getting list of jobs

Queue.scheduled_jobs is a generator that produces the jobs that are currently scheduled for a particular queue.
Scheduler.schedule returns a list of job ids and scheduled time.

Checking if a job is scheduled

You can check if a job or job id is currently scheduled. Example: job in queue

Unscheduling jobs

You can unschedule jobs with Queue.remove_job. This removes the job from the scheduler queue but does not remove it from RQ.

Repeating jobs

Once a job has been enqueued you can set it to repeat with Queue.repeat which takes the job and a datetime.timedelta object. Additionally you can pass a max_runs value to limit the number of times it will repeat.

If the job is not already in the queue it will be enqueued at the given interval.

In order to ensure that job results cleanup doesn’t remove the job (thus breaking the repetition) the job is copied into a new job. The parent job can be accessed via Job.parent for the repeated jobs.

Due to how the jobs are put into the work queues the maximum frequency is controlled by the scheduler’s interval.

Scheduler

In order to move jobs from the schedule queue into the proper RQ queue a scheduler needs to be ran. This can be accomplished via the rqscheduler script. Additionally, you can extend from rq_retry_scheduler.Scheduler to customize the functonality.

Worker

A worker is provided that will requeue jobs that fail using a defiend backoff strategy. The worker is designed to use the functionality from the Queue class to control the backoff.

The worker can be used by using the -w option to rq worker: rq worker -w 'rq_rety_scheduler.Worker.

The backoff times and total attempts is controlled by Worker.retry_delays.

Installation

Install via pip

pip install rq-retry-scheduler

Acknowledgements

This package was based heavily on the work of RQ Scheduler.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rq-retry-scheduler-0.2.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rq_retry_scheduler-0.2.1-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file rq-retry-scheduler-0.2.1.tar.gz.

File metadata

  • Download URL: rq-retry-scheduler-0.2.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for rq-retry-scheduler-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7f2c654a7e523e87cc497bec7d79f64df2b71568db8eb223f6c075c5e7f0a0da
MD5 5532a757eb98de7d48f5f70c1912dfe5
BLAKE2b-256 67c1242fb4118472e61fe67ba064fa7d49f5a4b60fe39c020022009a8b401704

See more details on using hashes here.

File details

Details for the file rq_retry_scheduler-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: rq_retry_scheduler-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for rq_retry_scheduler-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 52241bcc52de8d3b00112bcd069174389fc68ed03f3eb357d7cf664a15e4cccc
MD5 3aecefacb11e8691e3b4e46ccbd3a8fb
BLAKE2b-256 2731e444ff416f862bcb57d7d0619eab03b9beae594dc448b35ceb98494a2aa4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page