改成可配置的

This commit is contained in:
mark.tian
2025-12-09 22:01:27 +08:00
parent 38787b1e4e
commit f52b2c53df
4 changed files with 6 additions and 70 deletions

View File

@@ -2,6 +2,7 @@ from celery import Celery
from datetime import datetime
import logging
from logging_config import get_logger
from celery_config import CELERY_CONFIG
# 配置基本日志
logging.basicConfig(level=logging.INFO)
@@ -13,32 +14,10 @@ celery_logger = get_logger('celery_app')
# 创建Celery应用
app = Celery(
'tasks',
broker='redis://localhost:6379/0',
backend='redis://localhost:6379/0',
include=['call_api_task']
broker=CELERY_CONFIG['broker_url'],
backend=CELERY_CONFIG['result_backend'],
include=CELERY_CONFIG['include']
)
# 配置Celery
app.conf.update(
timezone='Asia/Shanghai',
enable_utc=False,
broker_url='redis://localhost:6379/0',
result_backend='redis://localhost:6379/0',
task_serializer='json',
accept_content=['json'],
result_serializer='json',
ask_track_started=True,
# Beat 调度配置
# crontab(hour=9, minute=0), # 每天上午9点执行
beat_schedule={
'daily-morning-task': {
'task': 'call_api',
'schedule': 60.0 * 2.0
},
},
# Flower监控配置
worker_send_task_events=True,
task_send_sent_event=True,
)
app.conf.update(CELERY_CONFIG)