我正在使用
http://python-rq.org/在Heroku worker dynos上排队并执行任务.这些是长时间运行的任务,偶尔我需要在执行中期取消它们.我怎么用Python做到这一点?
from redis import Redis from rq import Queue from my_module import count_words_at_url q = Queue(connection=Redis()) result = q.enqueue( count_words_at_url,'http://nvie.com')
后来我想做一个单独的过程:
from redis import Redis from rq import Queue from my_module import count_words_at_url q = Queue(connection=Redis()) result = q.revoke_all() # or something
谢谢!
解决方法
如果你手头有工作实例
job.cancel()
或者,如果您可以确定哈希:
from rq import cancel_job cancel_job('2eafc1e6-48c2-464b-a0ff-88fd199d039c')
但这只是将它从队列中删除;我不知道如果已经执行它会杀死它.
您可以让它记录墙壁时间,然后定期检查自己并在一段时间后引发异常/自毁.
对于手动,临时风格,死亡:如果你安装了redis-cli,你可以做一些像flushall队列和工作那样激烈的事情:
$redis-cli 127.0.0.1:6379> flushall OK 127.0.0.1:6379> exit
I’m still digging around the documentation尝试找到如何进行精确杀戮.
不确定这是否对任何人都有帮助,因为问题已经是18个月了.