SuperAPI AI 工具集

celery-config-patterns

部署与运维

查看项目

更新于 10-16 05:45

技能介绍

用途:为 Python 项目提供 Celery 配置模板与配套脚本,覆盖首次配置、Django/Flask/FastAPI/独立应用集成、Redis 或 RabbitMQ broker 设置、生产级配置、任务路由与队列、监控与日志、跨框架配置迁移。

主要能力:提供各框架的 Celery app 模板(celery-app-django.py、celery-app-flask.py、celery-app-fastapi.py、celery-app-standalone.py),broker 配置模板(config-redis.py、config-rabbitmq.py),示例任务与 Beat 调度模板;脚本包括 detect-framework.sh 检测框架、generate-config.sh 生成配置、validate-config.sh 校验配置、test-broker-connection.sh 测试 broker 连通性。

使用方式:先运行 bash scripts/detect-framework.sh 检测框架;按框架选用对应模板(Django 放 projectname/celery.py,Flask/FastAPI 放 app/celery.py 或 celery.py,独立应用放 celery_app.py);选择 broker 模板后用 bash scripts/generate-config.sh --framework=django --broker=redis 生成配置;启动前运行 bash scripts/validate-config.sh 校验,运行 bash scripts/test-broker-connection.sh 测试连接。示例:CELERY_BROKER_URL = 'redis://localhost:6379/0';RabbitMQ 使用 CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//' 与 CELERY_RESULT_BACKEND = 'rpc://'。

安全与限制:凭据通过环境变量读取,示例使用占位符,不硬编码密码,.env 应加入 .gitignore,并提供 .env.example。依赖 celery>=5.3.0,Redis 需 redis>=4.5.0,RabbitMQ 需 kombu>=5.3.0;Django 可配 django-celery-beat、django-celery-results,Flask 可配 Flask-Celery,FastAPI 无需额外包。需要运行中的 redis-server(6379)或 rabbitmq-server(5672),以及 bash 与 python3(3.8+)。具体命令与配置以实际项目为准,版本、定价及未列出的平台信息暂未提供。