Download 3.0 PDF - Read the Docs

Transcript
Celery Documentation, Release 3.0.25
>>> res.get()
8
Calling a chain will return the result of the last task in the chain. You can get to the other tasks by following the
result.parent‘s:
>>> res.parent.get()
4
class celery.chord(header[, body ])
A chord consists of a header and a body. The header is a group of tasks that must complete before the callback
is called. A chord is essentially a callback for a group of tasks.
Example:
>>> res = chord([add.s(2, 2), add.s(4, 4)])(sum_task.s())
is effectively Σ((2 + 2) + (4 + 4)):
>>> res.get()
12
The body is applied with the return values of all the header tasks as a list.
class celery.subtask(task=None, args=(), kwargs={}, options={})
Describes the arguments and execution options for a single task invocation.
Used as the parts in a group or to safely pass tasks around as callbacks.
Subtasks can also be created from tasks:
>>> add.subtask(args=(), kwargs={}, options={})
or the .s() shortcut:
>>> add.s(*args, **kwargs)
Parameters
• task – Either a task class/instance, or the name of a task.
• args – Positional arguments to apply.
• kwargs – Keyword arguments to apply.
• options – Additional options to Task.apply_async().
Note that if the first argument is a dict, the other arguments will be ignored and the values in the dict will be
used instead.
>>> s = subtask("tasks.add", args=(2, 2))
>>> subtask(s)
{"task": "tasks.add", args=(2, 2), kwargs={}, options={}}
delay(*args, **kwargs)
Shortcut to apply_async().
apply_async(args=(), kwargs={}, ...)
Apply this task asynchronously.
Parameters
• args – Partial args to be prepended to the existing args.
232
Chapter 2. Contents