# flask_app/celery_app import os from celery import Celery # 创建 Celery 实例 celery_app = Celery( 'tasks', broker=os.getenv('CELERY_BROKER_URL', 'redis://redis:6379/0'), # 从环境变量加载 Broker 地址 backend=os.getenv('CELERY_RESULT_BACKEND', 'redis://redis:6379/0') # 从环境变量加载 Backend 地址 ) # 设置任务队列的速率限制(全局每分钟 250 次) celery_app.conf.task_annotations = { 'flask_app.task.process_qianwen_long': {'rate_limit': '250/m'} } # 可选:加载更多配置项(从环境变量或直接配置) celery_app.conf.update( timezone='UTC', # 设置时区(可根据需要修改) enable_utc=True # 确保 UTC 时间生效 ) celery_app.autodiscover_tasks(['flask_app.task'])