从django视图中取消或撤消eventlet中的celery任务

时间:2015-10-26 08:18:22

标签: python django celery eventlet

我正在尝试使用以下命令撤销芹菜任务。

revoke('d9078da5-9915-40a0-bfa1-392c7bde42ed', terminate=True, signal='SIGKILL')

revoke('d9078da5-9915-40a0-bfa1-392c7bde42ed', terminate=True)

revoke('d9078da5-9915-40a0-bfa1-392c7bde42ed')

这些都不起作用,我的工作池是eventlet:以

开头
$ celery -A scraper worker -P eventlet -c 1000 -l info

请告知如何执行此操作,因为我的django视图中有一个按钮,它使用任务I来取消任务。应该有办法做到这一点,但我不确定。使用prefork池它可以工作。

[2015-10-26 09:07:38,411: ERROR/MainProcess] pidbox command error: NotImplementedError("<class 'celery.concurrency.eventlet.TaskPool'> does not implement kill_job",)
Traceback (most recent call last):
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/kombu/pidbox.py", line 105, in dispatch
    reply = handle(method, kwdict(arguments))
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/kombu/pidbox.py", line 126, in handle_cast
    return self.handle(method, arguments)
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/kombu/pidbox.py", line 120, in handle
    return self.handlers[method](self.state, **arguments)
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/celery/worker/control.py", line 93, in revoke
    request.terminate(state.consumer.pool, signal=signum)
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/celery/worker/job.py", line 307, in terminate
    pool.terminate_job(self.worker_pid, signal)
  File "/Users/Michael/.virtualenvs/djangoscrape/lib/python2.7/site-packages/celery/concurrency/base.py", line 116, in terminate_job
    '{0} does not implement kill_job'.format(type(self)))
NotImplementedError: <class 'celery.concurrency.eventlet.TaskPool'> does not implement kill_job

1 个答案:

答案 0 :(得分:0)

错误消息说Celery的TaskPool(Eventlet兼容版本)没有此功能。因此,您可以自己实施并向Celery团队发送补丁,也可以留下功能请求并等待。

复制prefork TaskPool代码并使其适应Eventlet API greenthread.kill()应该非常容易。