54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from flask import Flask
|
|
from routes import api_bp
|
|
from config import config, APP_ENV
|
|
from task_queue_manager import init_queue_manager
|
|
import os
|
|
import logging
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
# 创建日志目录
|
|
log_dir = 'logs'
|
|
if not os.path.exists(log_dir):
|
|
os.makedirs(log_dir)
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s %(levelname)s %(name)s %(message)s',
|
|
handlers=[
|
|
# 文件处理器 - 记录到文件
|
|
RotatingFileHandler(
|
|
os.path.join(log_dir, 'app.log'),
|
|
maxBytes=10*1024*1024, # 10MB
|
|
backupCount=5
|
|
),
|
|
# 控制台处理器 - 输出到控制台
|
|
logging.StreamHandler()
|
|
]
|
|
)
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
# 加载配置
|
|
app.config.from_object(config.get(APP_ENV, config['default'])())
|
|
|
|
# 注册API蓝图
|
|
app.register_blueprint(api_bp)
|
|
|
|
# 初始化队列管理器
|
|
init_queue_manager()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("视频生成API服务启动中...")
|
|
print("核心API接口:")
|
|
print("1. 创建视频任务: POST /api/video/create")
|
|
print("2. 查询任务状态: GET /api/video/result/<task_id>")
|
|
print("3. 查询任务列表: GET /api/video/tasks")
|
|
print("4. 取消/删除任务: DELETE /api/video/cancel/<task_id>")
|
|
print("5. 健康检查: GET /health")
|
|
|
|
# app.run(host='0.0.0.0', port=5000, debug=True, threaded=True, use_reloader=True)
|
|
app.run(host='0.0.0.0', port=5000, debug=False, threaded=True, use_reloader=False) |