Task Scheduler
Scheduled tasks are stored in a Redis queue and executed by a runner. Tasks are set up on a cron which should be defined per-app in the tasks.py script in a schedule function, which is passed the scheduler when it is called:
from django_rq import job
def schedule(scheduler):
# At 3am every day
scheduler.cron("0 3 * * *", func=install_shrubbery)
@job
def install_shrubbery():
# note that no parameters can be passed
Upon deployment the Redis queues are cleared and then repopulated using two custom made management commands defined in core/management/commands.py
:
$ django clear_jobs
$ django scheduler
The scheduler
command runs through all apps installed locally and executes any schedule() function found in any tasks.py module to populate the job queues.