Creating an AsyncResult object from a task identifier is the recommended method in the FAQ to get the status of a task when the only thing you have is a task identifier.
However, compared to Celery 3.x, there are significant reservations that can bite people if they do not pay attention to them. It really depends on the specific use case.
By default, celery does not record the "running" state.
In order for the celery to record that the task is running, you must set CELERY_TRACK_STARTED to True . Here is a simple task that tests this:
@app.task(bind=True) def test(self): print self.AsyncResult(self.request.id).state
If CELERY_TRACK_STARTED is False , the default is to show PENDING status, even if the task is running. If you set CELERY_TRACK_STARTED to True , then the state will be STARTED .
PENDING means "I don't know."
An AsyncResult with a PENDING state does not mean anything except that celery does not know the status of the task. This may be due to any number of reasons.
On the one hand, AsyncResult can be constructed with invalid task identifiers. Such "tasks" will be considered pending Celery:
>>> task.AsyncResult("invalid").status 'PENDING'
Ok, so no one will feed explicitly invalid identifiers until AsyncResult . Fairly enough, it also has the effect that AsyncResult also consider a task that has successfully completed, but that Celery has forgotten as PENDING . Again, in some use cases this can be a problem. Part of the problem depends on how Celery is configured to save task results, because it depends on the presence of “tombstones” in the results database. (“Tombstones” is the term used in the celery documentation for data blocks that record how the task ended.) Using AsyncResult will not work at all if CELERY_IGNORE_RESULT is True . A more annoying problem is that celery destroys tombstones by default. By default, CELEREY_TASK_RESULT_EXPIRES set to 24 hours. Therefore, if you run the task and record the identifier in the long-term storage, and more than 24 hours later, you create AsyncResult with it, the status will be PENDING .
All "real tasks" begin in the PENDING state. Therefore, getting a PENDING task may mean that the task was requested, but never moved further than this (for any reason). Or it may mean that the problem is solved, but Celery forgot about his condition.
Oh! AsyncResult will not work for me. What else can I do?
I prefer to track goals, but to keep track of my tasks. I keep some information about the task, but it really is secondary to tracking goals. The targets are stored in the vault independently of Celery. When a request needs to perform calculations, it depends on the achievement of a specific goal, it checks whether the goal has been achieved, if so, it uses this cached goal, otherwise it starts a task that will affect the goal and sends the client that made HTTP -request with an answer that indicates that he should wait for the result.