如何清除队列中的Django RQ作业? [英] How to clear Django RQ jobs from a queue?

查看:376
本文介绍了如何清除队列中的Django RQ作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得有点愚蠢的问题,但似乎并不在于 RQ的文档。我有一个失败的队列,其中有数千个项目,我想使用Django管理界面清除它。管理界面列出它们,并允许我们单独删除并重新排队,但我不敢相信我必须潜入django shell才能批量进行。

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.

我错过了什么?

推荐答案

Queue class有一个 empty()可以访问的方法,如:

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

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

但是,在我的测试中,只清除了Redis中的失败的列表键,而不是工作键本身。所以你的成千上万的工作仍然会占据Redis的记忆。为了防止这种情况发生,您必须单独删除作业:

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

至于在管理界面中有一个按钮,您必须更改 django-rq /模板/ django-rq / jobs.html 模板,谁扩展了 admin / base_site.html ,似乎没有任何空间自定义。

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.

这篇关于如何清除队列中的Django RQ作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆