I'd like to use django_rq
and rq-scheduler
for offline tasks, but I'm unsure of where to call rq-scheduler
's ability to schedule repeating tasks. Right now, I've added my scheduling to a tasks.py
module in my app, and import that in __init__
.py. There has to be a better way to do this, though, right?
Thanks in advance.
RQ Scheduler is a small package that adds job scheduling capabilities to RQ, a Redis based Python queuing library.
Django-RQ is a simple app that allows you to configure your queues in django's settings.py and easily use them in your project.
The best place I've found to run it is from your AppConfig
in apps.py
.
def ready(self):
scheduler = django_rq.get_scheduler('default')
# Delete any existing jobs in the scheduler when the app starts up
for job in scheduler.get_jobs():
job.delete()
# Have 'mytask' run every 5 minutes
scheduler.schedule(datetime.utcnow(), 'mytask', interval=60*5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With