总的来说,我对 celery 和 django 很陌生,所以请原谅我缺乏知识。我正在尝试运行测试以进行一些计算并等待测试完成,以便我可以确保它完成了正确的答案。
这是我所拥有的:
在 app/tests.py
from tasks import *
c = calculate.apply_async(args=[1])
# wait until the task is done
while not calculate.AsyncResult(c.id).status == "SUCCESS":
print c.state
pass
在应用程序/tasks.py
from celery import shared_task
@shared_task
def calculate(proj_id):
#some calculations followed by a save of the object
即使在 celery 日志中表示任务已成功完成,状态也不会从挂起更改
[2014-06-10 17:55:11,417: INFO/MainProcess] Received task: app.tasks.calculate[1f11e7ab-0add-42df-beac-3d94c6868aac]
[2014-06-10 17:55:11,505: INFO/MainProcess] Task app.tasks.calculate[1f11e7ab-0add-42df-beac-3d94c6868aac] succeeded in 0.0864518239978s: None
我还在 mainapp/settings.py 中添加了 CELERY_IGNORE_RESULT = False,但这似乎没有任何作用。