backend-async-tasks
Installation
SKILL.md
Backend async tasks (Celery)
When to use
- You are adding or changing a Celery task in
backend/src/backend/apps/**/tasks.py. - You need to update the Celery Beat schedule in
backend/src/backend/celery_app.py. - You are adding DB access inside a Celery worker process.
Steps
- Define tasks only in a
tasks.pyfile under the relevant app module. - Decorate tasks with
@app.taskimported frombackend.celery_app. - Return a typed result (
int,None, etc.). Keep task-specific parameters local unless they must be environment-configured. - For DB access:
- Use
asyncio.run()to bridge async work. - Always acquire a session via
get_task_session()frombackend.celery_app.
- Use
- For periodic jobs, update
app.conf.beat_scheduleinbackend/src/backend/celery_app.pyand usecelery.schedules.crontab.