加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

取消Python RQ中已执行的任务?

发布时间:2020-12-16 21:42:26 所属栏目:Python 来源:网络整理
导读:我正在使用 http://python-rq.org/在Heroku worker dynos上排队并执行任务.这些是长时间运行的任务,偶尔我需要在执行中期取消它们.我怎么用Python做到这一点? from redis import Redisfrom rq import Queuefrom my_module import count_words_at_urlq = Que
我正在使用 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')

http://python-rq.org/contrib/

但这只是将它从队列中删除;我不知道如果已经执行它会杀死它.

您可以让它记录墙壁时间,然后定期检查自己并在一段时间后引发异常/自毁.

对于手动,临时风格,死亡:如果你安装了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个月了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读