我的应用程序A在应用程序B中调用一个芹菜任务长任务。然而,长任务是在B中注册的,而不是在A中注册的,所以A使用send_task调用它。我希望A中有一个机制来定期检查长任务是否完成。我该怎么做呢?
发布于 2018-12-07 18:23:03
send_task返回包含任务id的AsyncResult。您可以使用这个id定期检查长任务的结果。
result = my_app.send_task('longtask', kwargs={})
task_id = result.id
# anywhere else in your code you can reuse the
# task_id to check the status
from celery.result import AsyncResult
import time
done = False
while not done:
result = AsyncResult(task_id)
current_status = result.status
if current_status == 'SUCCESS':
print('yay! we are done')
done = True
time.sleep(10)https://stackoverflow.com/questions/53663707
复制相似问题