Results¶
Classes for querying task results.
AsyncResult¶
AsyncResult ¶
Bases: ResultBase
Query task state.
Arguments:
id (str): See :attr:id.
backend (Backend): See :attr:backend.
state
property
¶
The tasks current state.
Possible values includes:
*PENDING*
The task is waiting for execution.
*STARTED*
The task has been started.
*RETRY*
The task is to be retried, possibly because of failure.
*FAILURE*
The task raised an exception, or has exceeded the retry limit.
The :attr:`result` attribute then contains the
exception raised by the task.
*SUCCESS*
The task executed successfully. The :attr:`result` attribute
then contains the tasks return value.
result
property
¶
Task return value.
Note: When the task has been executed, this contains the return value. If the task raised an exception, this will be the exception instance.
get ¶
get(
timeout=None,
propagate=True,
interval=0.5,
no_ack=True,
follow_parents=True,
callback=None,
on_message=None,
on_interval=None,
disable_sync_subtasks=True,
EXCEPTION_STATES=states.EXCEPTION_STATES,
PROPAGATE_STATES=states.PROPAGATE_STATES,
)
Wait until task is ready, and return its result.
Warning:
Waiting for tasks within a task may lead to deadlocks.
Please read :ref:task-synchronous-subtasks.
Warning:
Backends use resources to store and transmit results. To ensure
that resources are released, you must eventually call
:meth:~@AsyncResult.get or :meth:~@AsyncResult.forget on
EVERY :class:~@AsyncResult instance returned after calling
a task.
Arguments:
timeout (float): How long to wait, in seconds, before the
operation times out. This is the setting for the publisher
(celery client) and is different from timeout parameter of
@app.task, which is the setting for the worker. The task
isn't terminated even if timeout occurs.
propagate (bool): Re-raise exception if the task failed.
interval (float): Time to wait (in seconds) before retrying to
retrieve the result. Note that this does not have any effect
when using the RPC/redis result store backends, as they don't
use polling.
no_ack (bool): Enable amqp no ack (automatically acknowledge
message). If this is :const:False then the message will
not be acked.
follow_parents (bool): Re-raise any exception raised by
parent tasks.
disable_sync_subtasks (bool): Disable tasks to wait for sub tasks
this is the default configuration. CAUTION do not enable this
unless you must.
Raises:
celery.exceptions.TimeoutError: if timeout isn't
:const:None and the result does not arrive within
timeout seconds.
Exception: If the remote call raised an exception then that
exception will be re-raised in the caller process.
ready ¶
Return :const:True if the task has executed.
If the task is still running, pending, or is waiting
for retry then :const:False is returned.
revoke ¶
Send revoke signal to all workers.
Any worker receiving the task, or having reserved the task, must ignore it.
Arguments:
terminate (bool): Also terminate the process currently working
on the task (if any).
signal (str): Name of signal to send to process if terminate.
Default is TERM.
wait (bool): Wait for replies from workers.
The timeout argument specifies the seconds to wait.
Disabled by default.
timeout (float): Time in seconds to wait for replies when
wait is enabled.
GroupResult¶
GroupResult ¶
Bases: ResultSet
Like :class:ResultSet, but with an associated id.
This type is returned by :class:~celery.group.
It enables inspection of the tasks state and return values as a single entity.
Arguments: id (str): The id of the group. results (Sequence[AsyncResult]): List of result instances. parent (ResultBase): Parent result of this group.
ResultSet¶
ResultSet ¶
Bases: ResultBase
A collection of results.
Arguments: results (Sequence[AsyncResult]): List of result instances.
get ¶
get(
timeout=None,
propagate=True,
interval=0.5,
callback=None,
no_ack=True,
on_message=None,
disable_sync_subtasks=True,
on_interval=None,
)
See :meth:join.
This is here for API compatibility with :class:AsyncResult,
in addition it uses :meth:join_native if available for the
current result backend.
ready ¶
Did all of the tasks complete? (either by success of failure).
Returns: bool: true if all of the tasks have been executed.
successful ¶
Return true if all tasks successful.
Returns: bool: true if all of the tasks finished successfully (i.e. didn't raise an exception).
failed ¶
Return true if any of the tasks failed.
Returns: bool: true if one of the tasks failed. (i.e., raised an exception)
join ¶
join(
timeout=None,
propagate=True,
interval=0.5,
callback=None,
no_ack=True,
on_message=None,
disable_sync_subtasks=True,
on_interval=None,
)
Gather the results of all tasks as a list in order.
Note: This can be an expensive operation for result store backends that must resort to polling (e.g., database).
You should consider using :meth:`join_native` if your backend
supports it.
Warning:
Waiting for tasks within a task may lead to deadlocks.
Please see :ref:task-synchronous-subtasks.
Arguments:
timeout (float): The number of seconds to wait for results
before the operation times out.
propagate (bool): If any of the tasks raises an exception,
the exception will be re-raised when this flag is set.
interval (float): Time to wait (in seconds) before retrying to
retrieve a result from the set. Note that this does not have
any effect when using the amqp result store backend,
as it does not use polling.
callback (Callable): Optional callback to be called for every
result received. Must have signature (task_id, value)
No results will be returned by this function if a callback
is specified. The order of results is also arbitrary when a
callback is used. To get access to the result object for
a particular id you'll have to generate an index first:
index = {r.id: r for r in gres.results.values()}
Or you can create new result objects on the fly:
result = app.AsyncResult(task_id) (both will
take advantage of the backend cache anyway).
no_ack (bool): Automatic message acknowledgment (Note that if this
is set to :const:False then the messages
will not be acknowledged).
disable_sync_subtasks (bool): Disable tasks to wait for sub tasks
this is the default configuration. CAUTION do not enable this
unless you must.
Raises:
celery.exceptions.TimeoutError: if timeout isn't
:const:None and the operation takes longer than timeout
seconds.
EagerResult¶
EagerResult ¶
Bases: AsyncResult
Result that we know has already been executed.