改成可配置的
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user