Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Django RQ jobs from a queue?

I feel a bit stupid for asking, but it doesn't appear to be in the documentation for RQ. I have a 'failed' queue with thousands of items in it and I want to clear it using the Django admin interface. The admin interface lists them and allows me to delete and re-queue them individually but I can't believe that I have to dive into the django shell to do it in bulk.

What have I missed?

like image 986
Joe Avatar asked Aug 07 '13 13:08

Joe


2 Answers

The Queue class has an empty() method that can be accessed like:

import django_rq
q = django_rq.get_failed_queue()
q.empty()

However, in my tests, that only cleared the failed list key in Redis, not the job keys itself. So your thousands of jobs would still occupy Redis memory. To prevent that from happening, you must remove the jobs individually:

import django_rq
q = django_rq.get_failed_queue()
while True:
    job = q.dequeue()
    if not job:
        break
    job.delete()  # Will delete key from Redis

As for having a button in the admin interface, you'd have to change django-rq/templates/django-rq/jobs.html template, who extends admin/base_site.html, and doesn't seem to give any room for customizing.

like image 179
augustomen Avatar answered Sep 22 '22 16:09

augustomen


The redis-cli allows FLUSHDB, great for my local environment as I generate a bizzallion jobs.

With a working Django integration I will update. Just adding $0.02.

like image 35
Marc Avatar answered Sep 22 '22 16:09

Marc