芹菜result.get超时 [英] Celery result.get times out
问题描述
我有两个不同的Django项目,分别是 projA
和 projB
,每个项目都有自己的celery守护程序在不同的队列上运行但同一个虚拟主机,projA的任务为 taskA
,projB的任务为 taskB
,我尝试运行 taskB
从 taskA
内部,例如
I have two different django projects say projA
and projB
, each have its own celery daemon running on separate queues but same vhost, projA have a task taskA
and projB have a task taskB
, I try to run taskB
from inside taskA
e.g.
@task(routing_key='taskA')
def taskA(event_id):
# do some work , then call taskB and wait for result
result = send_task('taskB',routing_key='taskB')
res = result.get(timeout=20)
我可以看到在projB的日志中,taskB在一秒钟内完成,但是taskA继续等待结果,并在20秒后超时。
I can see in logs of projB that taskB finished within a second, but taskA keeps on waiting for result and times out after 20 seconds
对于后端,我有Rabbitmq。
For backend I have rabbitmq.
推荐答案
设置结果后端解决了问题
Setting the result back-end fixed the problem
CELERY_RESULT_BACKEND = "amqp"
CELERY_AMQP_TASK_RESULT_EXPIRES = 1000
IMO(如果结果)后端未设置result.get应该引发错误或至少记录警告
IMO if result back-end is not set result.get should throw error or at-least log a warning
尽管celery 2.3确实引发了错误,如此处所述 https://github.com/ask/django-celery/issues/66
Though celery 2.3 does throw error as described here https://github.com/ask/django-celery/issues/66
这篇关于芹菜result.get超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!