如何清除队列中的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.