Retrieve task result by id in Celery

喜欢而已 提交于 2019-11-29 01:07:26
Demetris

It works using AsyncResult. (see this answer)

So first create the task:

from cel.tasks import add
res = add.delay(3,4)
res.status
'SUCCESS'
res.id
'432890aa-4f02-437d-aaca-1999b70efe8d'

Then start another python shell:

from celery.result import AsyncResult
from cel.tasks import app
res = AsyncResult('432890aa-4f02-437d-aaca-1999b70efe8d',app=app)
res.state
'SUCCESS'
res.get()
7

This is due to RabbitMQ not actually storing the results. If you need the ability to get the results later on, use redis or SQL as the result backend.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!