Skip to main content

AsyncBackendMixin

Mixin for backends that enables the async API.

Attributes

AttributeTypeDescription
result_consumer[ResultConsumer](../rpc/resultconsumer.md?sid=celery_backends_rpc_resultconsumer)The consumer instance responsible for managing result buckets, drainers, and message consumption for asynchronous tasks.
_pending_messagesMessageBufferA buffer containing messages that have been received but not yet processed or resolved into result objects.
_pending_resultstupleA tuple containing two mappings (concrete and weak) used to track active task IDs and their corresponding result objects.
is_asyncboolean = TrueA read-only flag indicating that the backend supports the asynchronous API.

Methods


iter_native()

@classmethod
def iter_native(
result: [ResultSet](../../result/resultset.md?sid=celery_result_resultset),
no_ack: boolean = True
) - > generator

Iterates over results as they become available from the native backend, yielding task IDs and their associated data.

Parameters

NameTypeDescription
result[ResultSet](../../result/resultset.md?sid=celery_result_resultset)The set of results to iterate over and monitor for completion
no_ackboolean = TrueWhether to disable manual acknowledgment of messages from the underlying transport

Returns

TypeDescription
generatorA generator yielding tuples of (task_id, result_data) for each completed task

add_pending_result()

@classmethod
def add_pending_result(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult),
weak: boolean = False,
start_drainer: boolean = True
) - > [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)

Adds a result to the tracking system and initiates the background drainer to start listening for its completion.

Parameters

NameTypeDescription
result[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object to begin tracking for asynchronous updates
weakboolean = FalseIf true, the result is stored using a weak reference to allow for earlier garbage collection
start_drainerboolean = TrueWhether to immediately start the result consumer's background event loop

Returns

TypeDescription
[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object that was added to the pending tracking system

add_pending_results()

@classmethod
def add_pending_results(
results: list,
weak: boolean = False
) - > list

Registers multiple result objects for tracking and ensures the result consumer drainer is active.

Parameters

NameTypeDescription
resultslistA collection of AsyncResult objects to be tracked asynchronously
weakboolean = FalseIf true, all results in the list will be stored as weak references

Returns

TypeDescription
listA list of the AsyncResult objects that were added to the tracking system

remove_pending_result()

@classmethod
def remove_pending_result(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
) - > [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)

Removes a result from the pending tracking system and performs cleanup actions once the result is fulfilled.

Parameters

NameTypeDescription
result[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object to stop tracking

Returns

TypeDescription
[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object that was removed from tracking

on_result_fulfilled()

@classmethod
def on_result_fulfilled(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)
) - > null

Handles cleanup for a fulfilled result by canceling any active subscriptions for its task ID in the consumer.

Parameters

NameTypeDescription
result[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object that has been successfully resolved

Returns

TypeDescription
null

wait_for_pending()

@classmethod
def wait_for_pending(
result: [AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult),
callback: callable = null,
propagate: boolean = True
) - > object

Blocks until the specified result is ready, optionally propagating exceptions or executing a callback upon completion.

Parameters

NameTypeDescription
result[AsyncResult](../../result/asyncresult.md?sid=celery_result_asyncresult)The result object to wait for
callbackcallable = nullAn optional function to execute once the result is ready
propagateboolean = TrueWhether to raise the task's exception if the task failed

Returns

TypeDescription
objectThe resolved value of the result, or raises an exception if propagate is True

is_async()

@classmethod
def is_async() - > boolean

Indicates whether the backend supports asynchronous operations.

Returns

TypeDescription
booleanAlways returns True for this mixin