搜索

PythonReactSEOPDF
GitHub Skill

backend-async-tasks

Use when creating or updating Celery tasks, async job logic, or Beat schedules in the backend.

lmiguelvargasf☆ 2 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

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

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!