A database backed job scheduler for Django RQ.
Currently, when you pip install Django RQ Scheduler the following packages are also installed.
- django >= 1.9
- django-model-utils >= 2.4
- django-rq >= 2.0 (Django RQ requires RQ >= 1.0 due to changes in redis >= 3)
- rq-scheduler >= 0.9.0
- pytz >= 2015.7
- croniter >= 0.3.24
Testing also requires:
- factory_boy >= 2.6.1
- psycopg2 >= 2.6.1
- fakeredis >= 1
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
The last step is migrate the database:
./manage.py migrate
See http://python-rq.org/docs/jobs/ or https://github.com/ui/django-rq#job-decorator
An example:
myapp.jobs.py
@job
def count():
return 1 + 1
-
Sign into 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.
-
Sign into 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.
- The result TTL must be either indefinite
-1
, unset, or greater than this interval. - The Interval must be a multiple of the scheduler's interval. With a default config this interval is 60 seconds and is only a consideration when using
seconds
as the Interval Unit. If a shorter interval is needed rq-scheduler's interval can be changed by settingDJANGO_RQ_SCHEDULER_INTERVAL
to something other than60
; it's advised to set it to a divisor of60
.
- The result TTL must be either indefinite
-
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.
IMPORTANT NOTE (from django-rq): If you set up a repeated job, you must make sure that you
either do not set a result_ttl
(by setting as -1) value or you set a value larger than the interval (in seconds).
Otherwise, the entry with the job details will expire and the job will not get re-scheduled.
Please report issues via GitHub Issues .