Track Results and Handle Failures
Poll task state and retry on error.
The AsyncResult Handle
When you enqueue a task you get an AsyncResult. Save its id so you can check on the job from any later request.
job = add.delay(2, 3)
ticket = job.idCheck the State
Each job has a state like PENDING, STARTED, SUCCESS, or FAILURE. You read it to know whether the work is done.
res = add.AsyncResult(ticket)
print(res.state)All lessons in this course
- Why Move Work Off the Request
- Wire Celery into the App Factory
- Define and Call a Task
- Track Results and Handle Failures