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

标签 python heroku redis python-rq

我正在使用 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 queues 和 jobs 这样激烈的事情:

$ redis-cli
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> exit

I'm still digging around the documentation尝试找出如何进行精确杀伤。

不确定这是否对任何人有帮助,因为这个问题已经 18 个月了。

关于python - 取消 Python RQ 中已经执行的任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16793879/

相关文章:

Python 合并两个 csv 文件 python

ruby-on-rails - rails 中的线程会自动打开数据库连接吗?

heroku - Gandi.net 和 Heroku 域路由

javascript - NodeJS Redis session 不会通过浏览器重定向持续存在

php - 如何从 php 用户输入创建 redis key ?

python - 何时在单热编码 ML 工作负载中使用暗阵列与 dask 数据帧

python - Django REST 用户创建/身份验证

redis - 可以在redis中存储排序集的最大值/精度是多少

python - 每次函数运行时增加计数

heroku - 什么是单个 Heroku Web Dyno?