Celery Task Lifecycle States
The Celery Task Lifecycle diagram illustrates the various states a task transitions through from its initial submission to its final resolution.
Key components and transitions:
- Celery Task Lifecycle States: The initial state of a task. It is the default state when a task is first submitted and before it is picked up by a worker.
- Celery Task Lifecycle States: A state used primarily in events to indicate that a worker has received the task message from the broker.
- Celery Task Lifecycle States: Indicates that a worker has begun executing the task. This state is only recorded if the
task_track_startedsetting is enabled. - Celery Task Lifecycle States: A terminal state indicating the task completed successfully and returned a result.
- Celery Task Lifecycle States: A terminal state indicating the task failed with an exception or exceeded its retry limit.
- Celery Task Lifecycle States: A state indicating the task failed but is being rescheduled for another attempt. This leads back to the
PENDINGstate for the next execution. - Celery Task Lifecycle States: A terminal state indicating the task was cancelled, either before it started or while it was running (terminated).
- Celery Task Lifecycle States: A state (mostly for events) indicating the worker rejected the task, for example, if it was malformed or expired.
- Celery Task Lifecycle States: A state indicating the task was intentionally ignored by the user (e.g., via an
Ignoreexception).
The diagram shows the flow from submission through the worker's handling logic, including the possibility of retries and revocations at different stages.
Key Architectural Findings:
- States are defined as constants in
celery/states.py. PENDINGis the default state in the result backend when no record exists for a task ID.RECEIVEDandREJECTEDare primarily event-driven states and are not typically persisted in result backends.STARTEDstate tracking is optional and depends on thetask_track_startedconfiguration.RETRYtriggers the creation of a new task message, effectively restarting the lifecycle for that task ID.REVOKEDcan be reached fromPENDING,RECEIVED, orSTARTEDstates if a revocation signal is received or the task is found in the revoked list.IGNOREDis a specific state reached when a task raises thecelery.exceptions.Ignoreexception.
Loading diagram...