Slide 20
Slide 20 text
# signatures allow complex configurations
>>> from celery import chain, group
# we can bind arguments to functions
# without executing them
>>> step1 = mul.s(3, 4)
>>> step1
tasks.mul(3, 4)
# ... which allows us to combine tasks
>>> step2 = chain(add.s(1, 2), mul.s(3))
>>> step2
tasks.add(1, 2) | mul(3)
# various combinations are possible
>>> step3 = chain(group(step1, step2),
... aggr.s(func=add))
>>> step3
%tasks.aggr(...)
>>> result = step3.delay()
>>> result.get()
$ python -i tasks.py
from functools import reduce
from celery import Celery
cl = Celery('tasks',
broker='...', backend='...')
@cl.task
def add(x, y):
return x + y
@cl.task
def mul(x, y):
return x * y
@cl.task
def aggr(numbers, func=None):
return reduce(func, numbers)
$ cat tasks.py
$ celery worker -A tasks