39

I store the task_id from an celery.result.AsyncResult in a database and relate it to the item that the task affects. This allows me to perform a query to retrieve all the task_ids of tasks that relate to a specific item.

So after retrieving the task_id from the database, how do I go about retrieving information about the task's state/result/etc?

bradley.ayers
  • 37,165
  • 14
  • 93
  • 99

1 Answers1

67

From the Celery FAQ:

result = MyTask.AsyncResult(task_id)
result.get()
miles82
  • 6,584
  • 38
  • 28
  • 13
    Note this won't work in testing (i.e. if `CELERY_ALWAYS_EAGER` is `True`). See https://github.com/celery/celery/issues/2275 – turtlemonvh Sep 23 '14 at 23:11
  • Reference an example at https://stackoverflow.com/questions/30753040/retrieve-task-result-by-id-in-celery – zerocog Jul 14 '17 at 00:16