A database backed job scheduler for Django RQ with Django
Project description
Django RQ Scheduler
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
-
Use pip to install:
pip install django-rq-scheduler
-
In
settings.py
, adddjango_rq
andscheduler
toINSTALLED_APPS
:INSTALLED_APPS = [ ... 'django_rq', 'scheduler', ... ]
-
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, }, }
-
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
-
Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.
-
Click on the Add link for Scheduled Job.
-
Enter a unique name for the job in the Name field.
-
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
-
Choose your Queue. Side Note: The queues listed are defined in the Django Settings.
-
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.
-
Click the Save button to schedule the job.
Repeatable Job
-
Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.
-
Click on the Add link for Repeatable Job
-
Enter a unique name for the job in the Name field.
-
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
-
Choose your Queue. Side Note: The queues listed are defined in the Django Settings.
-
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.
-
Enter an Interval, and choose the Interval unit. This will calculate the time before the function is called again.
-
In the Repeat field, enter the number of time the job is to be ran. Leaving the field empty, means the job will be scheduled to run forever.
-
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
-
Sign in to the Django Admin site, http://localhost:8000/admin/ and locate the Django RQ Scheduler section.
-
Click on the Add link for Scheduled Job.
-
Enter a unique name for the job in the Name field.
-
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
-
Choose your Queue. Side Note: The queues listed are defined in the Django Settings.
-
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.
-
Click the Save button to schedule the job.
-
Add arguments to the job, pick argument type.
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_rq_scheduler-2022.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2efb4f2b721518a42fbdc85f18d3d7da2052d19cbc03662946db08d8906e3a6 |
|
MD5 | 92c47e8a5cfc602e03ccee9912a75819 |
|
BLAKE2b-256 | 63c27a88ebae2c16cd9b60f1438aafc7adeb247b608cf8d93898031ff5a5cb84 |
Hashes for django_rq_scheduler-2022.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5ec1a8c69c58d560173ea6f879433e5a781170f96cacd19597da773b550102 |
|
MD5 | 55dbfecda8d514226f9fff314817b394 |
|
BLAKE2b-256 | bbd459157bb3f488711d0e4df7e6f1c8d8c76c8067f508686f9ffd68ac84906e |