# Lmiguelvargasf Nova Backend Async Tasks

> Backend async tasks (Celery)

- Skill: `tomevault-io/lmiguelvargasf-nova-backend-async-tasks` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/lmiguelvargasf-nova-backend-async-tasks`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/lmiguelvargasf-nova-backend-async-tasks/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/lmiguelvargasf-nova-backend-async-tasks

---


# 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

1. Define tasks only in a `tasks.py` file under the relevant app module.
2. Decorate tasks with `@app.task` imported from `backend.celery_app`.
3. Return a typed result (`int`, `None`, etc.). Keep task-specific parameters
   local unless they must be environment-configured.
4. For DB access:
   - Use `asyncio.run()` to bridge async work.
   - Always acquire a session via `get_task_session()` from `backend.celery_app`.
5. For periodic jobs, update `app.conf.beat_schedule` in
   `backend/src/backend/celery_app.py` and use `celery.schedules.crontab`.

## Constraints and guardrails

- Never use the global `alchemy_config` engine inside a task; it is not fork-safe
   for Celery workers.
- Always use `get_task_session()` to manage DB connections safely across worker
   processes.

## References

- `backend/src/backend/apps/**/tasks.py`
- `backend/src/backend/celery_app.py`
- `backend/tests/apps/users/test_tasks.py`

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/lmiguelvargasf) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

