RQ - 空 &删除队列 [英] RQ - Empty & Delete Queues
问题描述
我正在使用 RQ,我有一个 failed
队列,有数千个项目和另一个 test
队列我创建了一段时间来测试,现在是空的和未使用的.我想知道如何从 failed
队列中删除所有作业,并完全删除 test
队列?
对基本问题表示歉意,但我在 RQ 文档 中找不到相关信息,而且我对 Redis 和 RQ 都是全新的……提前致谢!
使用 rq 清理
RQ 提供了使任何队列为空的方法:
<预><代码>>>>从 redis 导入 Redis>>>从 rq 导入队列>>>qfail = Queue("失败", connection=Redis())>>>qfail.count8>>>qfail.empty()8L>>>qfail.count0您可以对 test
队列执行相同的操作,如果它仍然存在.
使用 rq-dashboard
进行清理安装 rq-dashboard:
$ pip install rq-dashboard
开始:
$ rq-dashboardRQ 仪表板,版本 0.3.4* 在 http://0.0.0.0:9181/上运行
在浏览器中打开.
选择队列
点击红色按钮清空"
大功告成.
Python 函数清除作业
如果您运行的 Redis 太旧,在 RQ 使用的命令上失败,您仍然可能会成功删除通过python代码工作:
代码采用队列的名称,其中是作业 ID.
使用 LPOP,我们要求工作 ID 加一.
为作业 ID 添加前缀(默认为rq:job:")我们有一个键,作业存储在哪里.
对每个键使用 DEL,我们逐个清除数据库作业.
<预><代码>>>>导入redis>>>r = redis.StrictRedis()>>>qname = "rq:queue:failed">>>def purgeq(r, qname):...而真:... jid = r.lpop(qname)...如果 jid 为 None:... 休息... r.delete("rq:job:" + jid)... 打印 jid...>>>清除(r,qname)a0be3624-86c1-4dc4-bb2e-2043d2734b7b3796c312-9b02-4a77-be89-249aa7325c25ca65f2b8-044c-41b5-b5ac-cefd56699758896f70a7-9a35-4f6b-b122-a08513022bc5I'm using RQ, and I have a failed
queue with thousands of items, and another test
queue I created a while back for testing which is now empty and unused. I'm wondering how to remove all jobs from the failed
queue, and delete the test
queue altogether?
Apologies for the basic question, but I can't find info on this in the RQ docs, and I'm completely new to both Redis and RQ... Thanks in advance!
Cleanup using rq
RQ offers methods to make any queue empty:
>>> from redis import Redis
>>> from rq import Queue
>>> qfail = Queue("failed", connection=Redis())
>>> qfail.count
8
>>> qfail.empty()
8L
>>> qfail.count
0
You can do the same for test
queue, if you have it still present.
Cleanup using rq-dashboard
Install rq-dashboard:
$ pip install rq-dashboard
Start it:
$ rq-dashboard
RQ Dashboard, version 0.3.4
* Running on http://0.0.0.0:9181/
Open in browser.
Select the queue
Click the red button "Empty"
And you are done.
Python function Purge jobs
If you run too old Redis, which fails on command used by RQ, you still might sucess with deleting jobs by python code:
The code takes a name of a queue, where are job ids.
Usilg LPOP we ask for job ids by one.
Adding prefix (by default "rq:job:") to job id we have a key, where is job stored.
Using DEL on each key we purge our database job by job.
>>> import redis
>>> r = redis.StrictRedis()
>>> qname = "rq:queue:failed"
>>> def purgeq(r, qname):
... while True:
... jid = r.lpop(qname)
... if jid is None:
... break
... r.delete("rq:job:" + jid)
... print jid
...
>>> purge(r, qname)
a0be3624-86c1-4dc4-bb2e-2043d2734b7b
3796c312-9b02-4a77-be89-249aa7325c25
ca65f2b8-044c-41b5-b5ac-cefd56699758
896f70a7-9a35-4f6b-b122-a08513022bc5
这篇关于RQ - 空 &删除队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!