Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I register an rq-scheduler job in a Django app?

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.

like image 356
Carson Avatar asked Jul 08 '13 23:07

Carson


People also ask

What is RQ scheduler?

RQ Scheduler is a small package that adds job scheduling capabilities to RQ, a Redis based Python queuing library.

What is Django RQ?

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.


1 Answers

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)
like image 199
Aaron C. de Bruyn Avatar answered Sep 30 '22 01:09

Aaron C. de Bruyn