【发布时间】:2015-05-06 08:50:44
【问题描述】:
我想在 Celery + RabbitMQ 代理上通过清理过程实现任务取消。 如何在 Celery worker 中获取当前任务的“已撤销”状态?
# tasks.py -- celery worker
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
for i in range(0, 10):
time.sleep(1)
# I want check here for cleanup.
return x + y
# caller.py
from tasks import add
result = add.delay(4, 4)
result.revoke()
Celery 支持Abortable tasks,但它只适用于数据库后端。
Python 3.4.1 / Celery 3.1.17 / RabbitMQ 3.4.4
【问题讨论】: