Download Celery Documentation

Transcript
Celery Documentation, Release 3.1.19
AsyncResult.backend = None
The task result backend to use.
AsyncResult.build_graph(intermediate=False, formatter=None)
AsyncResult.children
AsyncResult.collect(intermediate=False, **kwargs)
Iterator, like get() will wait for the task to complete, but will also follow AsyncResult and
ResultSet returned by the task, yielding (result, value) tuples for each result in the tree.
An example would be having the following tasks:
from celery import group
from proj.celery import app
@app.task(trail=True)
def A(how_many):
return group(B.s(i) for i in range(how_many))()
@app.task(trail=True)
def B(i):
return pow2.delay(i)
@app.task(trail=True)
def pow2(i):
return i ** 2
Note that the trail option must be enabled so that the list of children is stored in result.children.
This is the default but enabled explicitly for illustration.
Calling collect() would return:
>>> from celery.result import ResultBase
>>> from proj.tasks import A
>>> result = A.delay(10)
>>> [v for v in result.collect()
... if not isinstance(v, (ResultBase, tuple))]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
AsyncResult.failed()
Returns True if the task failed.
AsyncResult.forget()
Forget about (and possibly remove the result of) this task.
AsyncResult.get(timeout=None,
propagate=True,
interval=0.5,
no_ack=True,
follow_parents=True, EXCEPTION_STATES=frozenset([’FAILURE’, ‘RETRY’,
‘REVOKED’]), PROPAGATE_STATES=frozenset([’FAILURE’, ‘REVOKED’]))
Wait until task is ready, and return its result.
Warning: Waiting for tasks within a task may lead to deadlocks. Please read Avoid launching
synchronous subtasks.
Parameters
• timeout – How long to wait, in seconds, before the operation times out.
• propagate – Re-raise exception if the task failed.
304
Chapter 2. Contents