Skip to content

Task States

Constants and sets for task state management.

State constants

Constant Value Description
PENDING "PENDING" Task is waiting for execution or unknown
RECEIVED "RECEIVED" Task received by a worker
STARTED "STARTED" Task has been started
SUCCESS "SUCCESS" Task executed successfully
FAILURE "FAILURE" Task execution failed
REVOKED "REVOKED" Task has been revoked
RETRY "RETRY" Task is being retried
REJECTED "REJECTED" Task was rejected by a worker
IGNORED "IGNORED" Task result was ignored

State sets

Set States Description
READY_STATES SUCCESS, FAILURE, REVOKED Task has finished executing
UNREADY_STATES PENDING, RECEIVED, STARTED, RETRY, REJECTED Task is not yet done
EXCEPTION_STATES FAILURE, RETRY, REVOKED Task raised an exception
PROPAGATE_STATES FAILURE, REVOKED Exceptions that should propagate to caller

Module reference

Built-in task states.

.. _states:

States

See :ref:task-states.

.. _statesets:

Sets

.. state:: READY_STATES

READY_STATES ~~~~~~~~~~~~

Set of states meaning the task result is ready (has been executed).

.. state:: UNREADY_STATES

UNREADY_STATES ~~~~~~~~~~~~~~

Set of states meaning the task result is not ready (hasn't been executed).

.. state:: EXCEPTION_STATES

EXCEPTION_STATES ~~~~~~~~~~~~~~~~

Set of states meaning the task returned an exception.

.. state:: PROPAGATE_STATES

PROPAGATE_STATES ~~~~~~~~~~~~~~~~

Set of exception states that should propagate exceptions to the user.

.. state:: ALL_STATES

ALL_STATES ~~~~~~~~~~

Set of all possible states.

Misc

PENDING module-attribute

PENDING = 'PENDING'

RECEIVED module-attribute

RECEIVED = 'RECEIVED'

STARTED module-attribute

STARTED = 'STARTED'

SUCCESS module-attribute

SUCCESS = 'SUCCESS'

FAILURE module-attribute

FAILURE = 'FAILURE'

REVOKED module-attribute

REVOKED = 'REVOKED'

RETRY module-attribute

RETRY = 'RETRY'

REJECTED module-attribute

REJECTED = 'REJECTED'

IGNORED module-attribute

IGNORED = 'IGNORED'

READY_STATES module-attribute

READY_STATES = frozenset({SUCCESS, FAILURE, REVOKED})

UNREADY_STATES module-attribute

UNREADY_STATES = frozenset(
    {PENDING, RECEIVED, STARTED, REJECTED, RETRY}
)

EXCEPTION_STATES module-attribute

EXCEPTION_STATES = frozenset({RETRY, FAILURE, REVOKED})

PROPAGATE_STATES module-attribute

PROPAGATE_STATES = frozenset({FAILURE, REVOKED})

ALL_STATES module-attribute

ALL_STATES = frozenset(
    {
        PENDING,
        RECEIVED,
        STARTED,
        SUCCESS,
        FAILURE,
        RETRY,
        REVOKED,
    }
)

state

Bases: str

Task state.

State is a subclass of :class:str, implementing comparison methods adhering to state precedence rules::

>>> from celery.states import state, PENDING, SUCCESS

>>> state(PENDING) < state(SUCCESS)
True

Any custom state is considered to be lower than :state:FAILURE and :state:SUCCESS, but higher than any of the other built-in states::

>>> state('PROGRESS') > state(STARTED)
True

>>> state('PROGRESS') > state('SUCCESS')
False

precedence

precedence(state: str) -> int

Get the precedence index for state.

Lower index means higher precedence.