Skip to main content

A database backed job scheduler for Django RQ with Django

Project description

Django RQ Scheduler

Django CI badge badge

Notice: Starting v2023.1, requirement for rq_scheduler was removed and instead one of the django-rq workers should run with --with-scheduler parameter as mentioned here.

A database backed job scheduler for Django RQ. Based on original django-rq-scheduler - Now supports Django 4.0.

This allows remembering scheduled jobs, their parameters, etc.

Installation

  1. Use pip to install:

    pip install django-rq-scheduler
    
  2. In settings.py, add django_rq and scheduler to INSTALLED_APPS:

    INSTALLED_APPS = [
        ...
        'django_rq',
        'scheduler',
        ...
    ]
    
  3. Configure Django RQ. See https://github.com/ui/django-rq#installation

    Add at least one Redis Queue to your settings.py:

    RQ_QUEUES = {
      'default': {
          'HOST': 'localhost',
          'PORT': 6379,
          'DB': 0,
          'PASSWORD': 'some-password',
          'DEFAULT_TIMEOUT': 360,
      },
    }
    
  4. Run migrations.

    ./manage.py migrate
    

Usage

Making a method in your code a schedulable job to be run by a worker.

See http://python-rq.org/docs/jobs/ or https://github.com/ui/django-rq#job-decorator

An example:

myapp.jobs.py

from django_rq import job

@job
def count():
    return 1 + 1

Scheduling a Job

Scheduled Job

  1. Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.

  2. Click on the Add link for Scheduled Job.

  3. Enter a unique name for the job in the Name field.

  4. In the Callable field, enter a Python dot notation path to the method that defines the job. For the example above, that would be myapp.jobs.count

  5. Choose your Queue. Side Note: The queues listed are defined in the Django Settings.

  6. Enter the time the job is to be executed in the Scheduled time field. Side Note: Enter the date via the browser's local timezone, the time will automatically convert UTC.

  7. Click the Save button to schedule the job.

Repeatable Job

  1. Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.

  2. Click on the Add link for Repeatable Job

  3. Enter a unique name for the job in the Name field.

  4. In the Callable field, enter a Python dot notation path to the method that defines the job. For the example above, that would be myapp.jobs.count

  5. Choose your Queue. Side Note: The queues listed are defined in the Django Settings.

  6. Enter the time the first job is to be executed in the Scheduled time field. Side Note: Enter the date via the browser's local timezone, the time will automatically convert UTC.

  7. Enter an Interval, and choose the Interval unit. This will calculate the time before the function is called again.

  8. In the Repeat field, enter the number of time the job is to be run. Leaving the field empty, means the job will be scheduled to run forever.

  9. Click the Save button to schedule the job.

Advanced usage using jobs with args

django-rq-scheduler supports

from django_rq import job
@job
def job_args_kwargs(*args, **kwargs):
    func = "test_args_kwargs({})"
    args_list = [repr(arg) for arg in args]
    kwargs_list = [k + '=' + repr(v) for (k, v) in kwargs.items()]
    return func.format(', '.join(args_list + kwargs_list))

Schedule job with custom arguments to be calculated when scheduling

  1. Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.

  2. Click on the Add link for Scheduled Job.

  3. Enter a unique name for the job in the Name field.

  4. In the Callable field, enter a Python dot notation path to the method that defines the job. For the example above, that would be myapp.jobs.job_args_kwargs

  5. Choose your Queue. Side Note: The queues listed are defined in the Django Settings.

  6. Enter the time the job is to be executed in the Scheduled time field. Side Note: Enter the date via the browser's local timezone, the time will automatically convert UTC.

  7. Click the Save button to schedule the job.

  8. Add arguments to the job, pick argument type.

  9. Add arguments with keys to the job, pick argument type and value.

Reporting issues or Features requests

Please report issues via GitHub Issues .

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

django_rq_scheduler-2023.1.0b3.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

django_rq_scheduler-2023.1.0b3-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file django_rq_scheduler-2023.1.0b3.tar.gz.

File metadata

File hashes

Hashes for django_rq_scheduler-2023.1.0b3.tar.gz
Algorithm Hash digest
SHA256 0638a447c94df58f9d583dc583ae931ffd82bae5b95bac09cab8a2578c6672ae
MD5 8cb60bb951f2aed1c83ec2d082b89294
BLAKE2b-256 87d92870e63c0e8108f6af1e4b6b21cf7cacce4b6fa088cddaa4ff6dd1e96d1b

See more details on using hashes here.

File details

Details for the file django_rq_scheduler-2023.1.0b3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_rq_scheduler-2023.1.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 ff4842ad5252482b0446a1fe1850995464af9ae21979c6e21b25a711748c593a
MD5 cc09a621a0f4f645c40c37dd67c273e8
BLAKE2b-256 807b6ca9291f2e2a2ca35d92ce82ac3448f781cb89aa80706d3614bb0992a024

See more details on using hashes here.

Supported by

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