Celery Python task queue
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
celery -A proj worker -l INFO
celery -A proj beat -l INFO
add.delay(2, 3)res.get(timeout=10)
celery -A proj status
celery -A proj inspect active
celery -A proj purge
celery -A proj call <task>
Concepts
- Your app task.delay()
- Broker RabbitMQ or Redis
- Worker runs the task
- Result backend optional, for .get()
Worker
celery -A proj worker -l INFO
-c <n>-Q <q1>,<q2>
-n <name>@%h
--autoscale=<max>,<min>
-B--time-limit <s>
--prefetch-multiplier <n>
Define and call
@app.task@shared_task@app.task(bind=True)
add.delay(2, 3)add.apply_async((2, 3), countdown=10)
apply_async(eta=<datetime>)
apply_async(queue="<q>")
add.s(2, 3)res.get(timeout=<s>)
res.ready() / res.state
Canvas
chain(a.s(), b.s())
a.s() | b.s() | c.s()
group(a.s(i) for i in r)
chord(group)(callback.s())
sig.set(queue="<q>")
Retries and errors
self.retry(exc=e, countdown=<s>)
autoretry_for=(<Exc>,)
retry_backoff=True
max_retries=<n>
acks_late=TrueRouting and config
task_routes = {"<task>": {"queue":
"<q>"}}
broker_url = "redis://localhost:6379/0"
result_backend = "redis://..."
task_always_eager = True
app.autodiscover_tasks()
Periodic tasks
celery -A proj beat -l INFO
beat_schedule = {...}
"schedule": 30.0
crontab(hour=7, minute=30)
crontab(minute="*/15")
Inspect and control
celery -A proj status
celery -A proj inspect active
celery -A proj inspect reserved
celery -A proj inspect registered
celery -A proj inspect -d <node> -j active
celery -A proj control revoke <id>
Operate
celery -A proj call <task> -a '[2, 3]'
celery -A proj purge -f
kill -TERM <pid>
Recipes
from celery import Celeryapp = Celery("proj", broker="redis://localhost", backend="redis://localhost")@app.taskdef add(x, y): return x + y
celery -A proj worker -l INFO# in a Python shellfrom proj import addr = add.delay(2, 3)r.get(timeout=10) # 5
@app.task(bind=True, autoretry_for=(IOError,), retry_backoff=True, max_retries=5)def fetch(self, url): ...
from celery import chord, groupchord(group(fetch.s(u) for u in urls))(merge.s())



