Query task state.
Attributes
| Attribute | Type | Description |
|---|
| app | [Celery](../app/base/celery.md?sid=celery_app_base_celery) = null | The Celery application instance associated with this result, used for accessing configuration and control methods. |
| TimeoutError | Exception = TimeoutError | Error raised for timeouts. |
| id | str = null | The task's UUID. |
| backend | [Backend](../backends/base/backend.md?sid=celery_backends_base_backend) = null | The task result backend to use. |
| wait | method | Wait until task is ready, and return its result. |
| maybe_reraise | method | Re-raises the task's exception if the task failed and propagation is enabled. |
| info | Any | Task return value; contains the return value on success or the exception instance on failure. |
| status | str | The 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
| Name | Type | Description |
|---|
| id | str | The unique identifier (UUID) of the task. |
| backend | [Backend](../backends/base/backend.md?sid=celery_backends_base_backend) = null | The result backend to use for retrieving task state. |
| task_name | str = null | Deprecated parameter for the name of the task. |
| app | [Celery](../app/base/celery.md?sid=celery_app_base_celery) = null | The Celery application instance. |
| parent | [AsyncResult](asyncresult.md?sid=celery_result_asyncresult) = null | The parent task result, if applicable. |
Methods
ignored()
@classmethod
def ignored() - > boolean
If True, task result retrieval is disabled.
Returns
| Type | Description |
|---|
boolean | The 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
| Name | Type | Description |
|---|
| callback | callable | The function to execute upon successful task completion |
| on_error | callable = null | The function to execute if the task fails |
| weak | boolean = false | If True, use a weak reference for the callback to allow garbage collection |
Returns
| Type | Description |
|---|
promise | A 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
| Type | Description |
|---|
tuple | A 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
| Type | Description |
|---|
list | A list containing the ID of this task and all its parent tasks |
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
| Name | Type | Description |
|---|
| connection | [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = null | The broker connection to use for sending the revoke signal |
| terminate | boolean = false | Also terminate the process currently working on the task (if any). |
| signal | string = null | Name of signal to send to process if terminate. Default is TERM. |
| wait | boolean = false | Wait for replies from workers. |
| timeout | float = null | Time in seconds to wait for replies when wait is enabled. |
@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
| Name | Type | Description |
|---|
| headers | dict | Headers to match when revoking tasks. |
| connection | [Connection](../worker/consumer/connection/connection.md?sid=celery_worker_consumer_connection_connection) = null | The broker connection to use for sending the revoke signal |
| terminate | boolean = false | Also terminate the process currently working on the task (if any). |
| signal | string = null | Name of signal to send to process if terminate. Default is TERM. |
| wait | boolean = false | Wait for replies from workers. |
| timeout | float = null | Time 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
| Name | Type | Description |
|---|
| timeout | float = null | How long to wait, in seconds, before the operation times out. |
| propagate | boolean = true | Re-raise exception if the task failed. |
| interval | float = 0.5 | Time to wait (in seconds) before retrying to retrieve the result. |
| no_ack | boolean = true | Enable amqp no ack (automatically acknowledge message). |
| follow_parents | boolean = true | Re-raise any exception raised by parent tasks. |
| callback | callable = null | Function to call when the result is retrieved |
| on_message | callable = null | Function to call for every message received |
| on_interval | callable = null | Function to call when waiting for the result |
| disable_sync_subtasks | boolean = true | Disable tasks to wait for sub tasks this is the default configuration. |
Returns
| Type | Description |
|---|
any | The 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
| Name | Type | Description |
|---|
| intermediate | boolean = false | If True, yield intermediate results in the dependency tree |
Returns
| Type | Description |
|---|
generator | Yields 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
| Type | Description |
|---|
any | The 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
| Name | Type | Description |
|---|
| intermediate | boolean = false | If True, include intermediate nodes even if they are not ready |
Returns
| Type | Description |
|---|
generator | Yields (parent, node) tuples for each dependency |
exists()
@classmethod
def exists() - > boolean
Return True if a result exists in the backend for this task.
Returns
| Type | Description |
|---|
boolean | True 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
| Type | Description |
|---|
boolean | True if the task is in a ready state (SUCCESS, FAILURE, etc.) |
successful()
@classmethod
def successful() - > boolean
Return True if the task executed successfully.
Returns
| Type | Description |
|---|
boolean | True if the task state is SUCCESS |
failed()
@classmethod
def failed() - > boolean
Return True if the task failed.
Returns
| Type | Description |
|---|
boolean | True if the task state is FAILURE |
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
| Name | Type | Description |
|---|
| propagate | boolean = true | Whether to raise the exception if the task failed |
| callback | callable = null | Optional function to call with the task ID and result |
Returns
| Type | Description |
|---|
any | The 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
| Name | Type | Description |
|---|
| intermediate | boolean = false | Whether to include intermediate tasks in the graph |
| formatter | [GraphFormatter](../utils/graph/graphformatter.md?sid=celery_utils_graph_graphformatter) = null | The formatter used to style the graph nodes and edges |
Returns
| Type | Description |
|---|
[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
| Type | Description |
|---|
[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
| Type | Description |
|---|
boolean | True if native join is supported |
children()
@classmethod
def children() - > list
Retrieves the list of child tasks spawned by this task.
Returns
| Type | Description |
|---|
list | A list of AsyncResult instances for child tasks |
result()
@classmethod
def result() - > any
Task return value.
Returns
| Type | Description |
|---|
any | The 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
| Type | Description |
|---|
string | The string representation of the stack trace |
state()
@classmethod
def state() - > string
The tasks current state.
Returns
| Type | Description |
|---|
string | The current status string (e.g., PENDING, SUCCESS, FAILURE) |
task_id()
@classmethod
def task_id() - > string
Compat. alias to id.
Returns
| Type | Description |
|---|
string | The task UUID |
name()
@classmethod
def name() - > string
Retrieves the name of the task from metadata.
Returns
| Type | Description |
|---|
string | The registered name of the task |
args()
@classmethod
def args() - > tuple
Retrieves the positional arguments used to call the task.
Returns
| Type | Description |
|---|
tuple | The task's positional arguments |
kwargs()
@classmethod
def kwargs() - > dict
Retrieves the keyword arguments used to call the task.
Returns
| Type | Description |
|---|
dict | The task's keyword arguments |
worker()
@classmethod
def worker() - > string
Retrieves the name of the worker that executed the task.
Returns
| Type | Description |
|---|
string | The worker node name |
date_done()
@classmethod
def date_done() - > datetime
UTC date and time.
Returns
| Type | Description |
|---|
datetime | The timestamp when the task reached a ready state |
retries()
@classmethod
def retries() - > int
Retrieves the number of times the task has been retried.
Returns
| Type | Description |
|---|
int | The retry count |
queue()
@classmethod
def queue() - > string
Retrieves the name of the queue the task was sent to.
Returns
| Type | Description |
|---|
string | The destination queue name |