Skip to main content

AsyncResult

Query task state.

Attributes

AttributeTypeDescription
app[Celery](../app/base/celery.md?sid=celery_app_base_celery) = nullThe Celery application instance associated with this result, used for accessing configuration and control methods.
TimeoutErrorException = TimeoutErrorError raised for timeouts.
idstr = nullThe task's UUID.
backend[Backend](../backends/base/backend.md?sid=celery_backends_base_backend) = nullThe task result backend to use.
waitmethodWait until task is ready, and return its result.
maybe_reraisemethodRe-raises the task's exception if the task failed and propagation is enabled.
infoAnyTask return value; contains the return value on success or the exception instance on failure.
statusstrThe tasks current state.

Constructor

Signature

def AsyncResult(
id: str,
backend: [Backend](../backends/base/backend.md?sid=celery_backends_base_backend) = null,
task_name: str = null,
app: [Celery](../app/base/celery.md?sid=celery_app_base_celery) = null,
parent: [AsyncResult](asyncresult.md?sid=celery_result_asyncresult) = null
) - > null

Parameters

NameTypeDescription
idstrThe unique identifier (UUID) of the task.
backend[Backend](../backends/base/backend.md?sid=celery_backends_base_backend) = nullThe result backend to use for retrieving task state.
task_namestr = nullDeprecated parameter for the name of the task.
app[Celery](../app/base/celery.md?sid=celery_app_base_celery) = nullThe Celery application instance.
parent[AsyncResult](asyncresult.md?sid=celery_result_asyncresult) = nullThe parent task result, if applicable.

Methods


ignored()

@classmethod
def ignored() - > boolean

If True, task result retrieval is disabled.

Returns

TypeDescription
booleanThe current status of result retrieval for this task

then()

@classmethod
def then(
callback: callable,
on_error: callable = null,
weak: boolean = false
) - > promise

Registers a callback to be executed when the task result becomes available.

Parameters

NameTypeDescription
callbackcallableThe function to execute upon successful task completion
on_errorcallable = nullThe function to execute if the task fails
weakboolean = falseIf True, use a weak reference for the callback to allow garbage collection

Returns

TypeDescription
promiseA promise object that resolves when the task completes

as_tuple()

@classmethod
def as_tuple() - > tuple

Serializes the task ID and its parent hierarchy into a nested tuple structure.

Returns

TypeDescription
tupleA tuple containing the task ID and its parent's tuple representation

as_list()

@classmethod
def as_list() - > list

Return as a list of task IDs.

Returns

TypeDescription
listA list containing the ID of this task and all its parent tasks

forget()

@classmethod
def forget()

Forget the result of this task and its parents.


revoke()

@classmethod
def revoke(
connection: [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = null,
terminate: boolean = false,
signal: string = null,
wait: boolean = false,
timeout: float = null
)

Send revoke signal to all workers.

Parameters

NameTypeDescription
connection[Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = nullThe broker connection to use for sending the revoke signal
terminateboolean = falseAlso terminate the process currently working on the task (if any).
signalstring = nullName of signal to send to process if terminate. Default is TERM.
waitboolean = falseWait for replies from workers.
timeoutfloat = nullTime in seconds to wait for replies when wait is enabled.

revoke_by_stamped_headers()

@classmethod
def revoke_by_stamped_headers(
headers: dict,
connection: [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = null,
terminate: boolean = false,
signal: string = null,
wait: boolean = false,
timeout: float = null
)

Send revoke signal to all workers only for tasks with matching headers values.

Parameters

NameTypeDescription
headersdictHeaders to match when revoking tasks.
connection[Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = nullThe broker connection to use for sending the revoke signal
terminateboolean = falseAlso terminate the process currently working on the task (if any).
signalstring = nullName of signal to send to process if terminate. Default is TERM.
waitboolean = falseWait for replies from workers.
timeoutfloat = nullTime in seconds to wait for replies when wait is enabled.

get()

@classmethod
def get(
timeout: float = null,
propagate: boolean = true,
interval: float = 0.5,
no_ack: boolean = true,
follow_parents: boolean = true,
callback: callable = null,
on_message: callable = null,
on_interval: callable = null,
disable_sync_subtasks: boolean = true
) - > any

Wait until task is ready, and return its result.

Parameters

NameTypeDescription
timeoutfloat = nullHow long to wait, in seconds, before the operation times out.
propagateboolean = trueRe-raise exception if the task failed.
intervalfloat = 0.5Time to wait (in seconds) before retrying to retrieve the result.
no_ackboolean = trueEnable amqp no ack (automatically acknowledge message).
follow_parentsboolean = trueRe-raise any exception raised by parent tasks.
callbackcallable = nullFunction to call when the result is retrieved
on_messagecallable = nullFunction to call for every message received
on_intervalcallable = nullFunction to call when waiting for the result
disable_sync_subtasksboolean = trueDisable tasks to wait for sub tasks this is the default configuration.

Returns

TypeDescription
anyThe task's return value on success. If the task failed and propagate is false, the raised exception instance is returned instead of being re-raised.

collect()

@classmethod
def collect(
intermediate: boolean = false
) - > generator

Collect results as they return.

Parameters

NameTypeDescription
intermediateboolean = falseIf True, yield intermediate results in the dependency tree

Returns

TypeDescription
generatorYields tuples containing the result instance of the child task, and the return value of that task.

get_leaf()

@classmethod
def get_leaf() - > any

Traverses the dependency tree and returns the result of the final leaf task.

Returns

TypeDescription
anyThe result of the last task in the dependency chain

iterdeps()

@classmethod
def iterdeps(
intermediate: boolean = false
) - > generator

Iterates over the dependency tree of the task.

Parameters

NameTypeDescription
intermediateboolean = falseIf True, include intermediate nodes even if they are not ready

Returns

TypeDescription
generatorYields (parent, node) tuples for each dependency

exists()

@classmethod
def exists() - > boolean

Return True if a result exists in the backend for this task.

Returns

TypeDescription
booleanTrue if the backend has a result stored for this task ID, False otherwise.

ready()

@classmethod
def ready() - > boolean

Return True if the task has executed.

Returns

TypeDescription
booleanTrue if the task is in a ready state (SUCCESS, FAILURE, etc.)

successful()

@classmethod
def successful() - > boolean

Return True if the task executed successfully.

Returns

TypeDescription
booleanTrue if the task state is SUCCESS

failed()

@classmethod
def failed() - > boolean

Return True if the task failed.

Returns

TypeDescription
booleanTrue if the task state is FAILURE

throw()

@classmethod
def throw()

Raises an exception on the promise associated with this result.


maybe_throw()

@classmethod
def maybe_throw(
propagate: boolean = true,
callback: callable = null
) - > any

Re-raises the task's exception if it failed and propagation is enabled.

Parameters

NameTypeDescription
propagateboolean = trueWhether to raise the exception if the task failed
callbackcallable = nullOptional function to call with the task ID and result

Returns

TypeDescription
anyThe task result or exception if not propagated

build_graph()

@classmethod
def build_graph(
intermediate: boolean = false,
formatter: [GraphFormatter](../utils/graph/graphformatter.md?sid=celery_utils_graph_graphformatter) = null
) - > [DependencyGraph](../utils/graph/dependencygraph.md?sid=celery_utils_graph_dependencygraph)

Constructs a dependency graph for the task and its dependencies.

Parameters

NameTypeDescription
intermediateboolean = falseWhether to include intermediate tasks in the graph
formatter[GraphFormatter](../utils/graph/graphformatter.md?sid=celery_utils_graph_graphformatter) = nullThe formatter used to style the graph nodes and edges

Returns

TypeDescription
[DependencyGraph](../utils/graph/dependencygraph.md?sid=celery_utils_graph_dependencygraph)A graph representing the task hierarchy

graph()

@classmethod
def graph() - > [DependencyGraph](../utils/graph/dependencygraph.md?sid=celery_utils_graph_dependencygraph)

Returns the dependency graph for this task.

Returns

TypeDescription
[DependencyGraph](../utils/graph/dependencygraph.md?sid=celery_utils_graph_dependencygraph)The cached dependency graph

supports_native_join()

@classmethod
def supports_native_join() - > boolean

Checks if the current backend supports native join operations.

Returns

TypeDescription
booleanTrue if native join is supported

children()

@classmethod
def children() - > list

Retrieves the list of child tasks spawned by this task.

Returns

TypeDescription
listA list of AsyncResult instances for child tasks

result()

@classmethod
def result() - > any

Task return value.

Returns

TypeDescription
anyThe return value of the task or the exception instance if it failed

traceback()

@classmethod
def traceback() - > string

Get the traceback of a failed task.

Returns

TypeDescription
stringThe string representation of the stack trace

state()

@classmethod
def state() - > string

The tasks current state.

Returns

TypeDescription
stringThe current status string (e.g., PENDING, SUCCESS, FAILURE)

task_id()

@classmethod
def task_id() - > string

Compat. alias to id.

Returns

TypeDescription
stringThe task UUID

name()

@classmethod
def name() - > string

Retrieves the name of the task from metadata.

Returns

TypeDescription
stringThe registered name of the task

args()

@classmethod
def args() - > tuple

Retrieves the positional arguments used to call the task.

Returns

TypeDescription
tupleThe task's positional arguments

kwargs()

@classmethod
def kwargs() - > dict

Retrieves the keyword arguments used to call the task.

Returns

TypeDescription
dictThe task's keyword arguments

worker()

@classmethod
def worker() - > string

Retrieves the name of the worker that executed the task.

Returns

TypeDescription
stringThe worker node name

date_done()

@classmethod
def date_done() - > datetime

UTC date and time.

Returns

TypeDescription
datetimeThe timestamp when the task reached a ready state

retries()

@classmethod
def retries() - > int

Retrieves the number of times the task has been retried.

Returns

TypeDescription
intThe retry count

queue()

@classmethod
def queue() - > string

Retrieves the name of the queue the task was sent to.

Returns

TypeDescription
stringThe destination queue name