是否取消Python RQ中已经执行的任务?
我正在使用Heroku worker dynos对任务进行排队和执行。这些是长时间运行的任务,有时我需要在执行过程中取消它们。如何从Python中实现这一点是否取消Python RQ中已经执行的任务?,python,heroku,redis,python-rq,Python,Heroku,Redis,Python Rq,我正在使用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, '
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
试着找出如何精确杀戮
不确定这是否有帮助,因为问题已经18个月了。我认为最常见的解决方案是让工作人员生成另一个线程/进程来执行实际工作,然后定期检查作业元数据。若要终止任务,请在元数据中设置一个标志,然后让工作线程终止正在运行的线程/进程。您有没有想过这一点?如果是这样,我希望你能发布解决方案。不幸的是,ThxI没有。我不得不绕开它。相关(但已关闭)github问题如下: