改成可配置的
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)
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""简化的API列表测试"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from api_config import API_CONFIG
|
||||
|
||||
def check_api_configs():
|
||||
"""检查配置文件中的API配置"""
|
||||
print("配置文件中的API配置列表:")
|
||||
print("=" * 30)
|
||||
|
||||
for api_name, api_config in API_CONFIG.items():
|
||||
print(f"🔧 {api_name}:")
|
||||
print(f" URL: {api_config['url']}")
|
||||
print(f" Method: {api_config['method']}")
|
||||
print(f" Timeout: {api_config['timeout']}")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_api_configs()
|
||||
@@ -1,20 +0,0 @@
|
||||
"""Flower监控配置"""
|
||||
|
||||
# Flower监控配置
|
||||
FLOWER_CONFIG = {
|
||||
'broker_url': 'redis://localhost:6379/0',
|
||||
'result_backend': 'redis://localhost:6379/0',
|
||||
'port': 5555,
|
||||
'address': '0.0.0.0', # 允许外部访问
|
||||
'basic_auth': 'admin:admin123', # 基础认证,格式: 'username:password'
|
||||
'oauth_redirect_url': None,
|
||||
'db': None, # 使用SQLite存储监控数据
|
||||
'inspect_timeout': 1000,
|
||||
'purge_offline_workers': 60,
|
||||
'max_tasks': 10000,
|
||||
'max_workers': 5000,
|
||||
'format_task': 'json',
|
||||
'enable_events': True,
|
||||
'tasks_columns': ['uuid', 'name', 'args', 'kwargs', 'state', 'runtime', 'worker', 'timestamp'],
|
||||
'workers_columns': ['hostname', 'pid', 'sw_ver', 'loadavg', 'active', 'processed', 'failed', 'status', 'last_heartbeat'],
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
from celery_app import app
|
||||
from flower_config import FLOWER_CONFIG
|
||||
from celery_config import FLOWER_CONFIG
|
||||
|
||||
def start_flower():
|
||||
"""启动Flower监控"""
|
||||
|
||||
Reference in New Issue
Block a user