Quickstart¶
1. Define tasks¶
proj/tasks.py
from potatoq import Potatoq
app = Potatoq("proj")
@app.task
def add(x, y):
return x + y
@app.task(bind=True, autoretry_for=(ConnectionError,), max_retries=5)
def fetch_avatar(self, user_id):
...
Potatoq("proj") finds its broker in this order:
broker=/app.conf.broker_url$POTATOQ_BROKER_URL(or$CELERY_BROKER_URL)- your Django
DATABASES["default"], if it's Postgres or SQLite sqlite:///potatoq.sqlite3, with a warning. That's fine for development.
2. Start a worker¶
$ potatoq -A proj.tasks worker
[INFO/MainProcess] potatoq 26.1 worker potatoq@laptop ready: broker=sqlite:///potatoq.sqlite3
results=sqlite:///potatoq.sqlite3 queues=default concurrency=8 (prefork) time_limit=1800s ...
The worker forks one process per available CPU. Each process runs one task at a time, so a slow task never holds others hostage. The same worker also runs your periodic tasks.
3. Send work¶
On the database brokers (SQLite, Postgres) results are stored automatically, because writing them costs nothing there. On Redis and RabbitMQ you opt in, as in Celery:
4. Look around¶
$ potatoq -A proj.tasks status # live workers and what they're running
$ potatoq -A proj.tasks queues # waiting tasks per queue
$ potatoq -A proj.tasks dead list # tasks that failed for good, and why
Where next¶
- Choose a broker: Postgres, Redis, RabbitMQ or SQLite?
- Django: zero configuration, tasks committed with your transactions
- Retries and failures: backoff, time limits, dead letters
- Migrating: from Celery (mostly a find-and-replace) or Dramatiq