ForcePilot/server/utils/lifespan.py

22 lines
537 B
Python
Raw Normal View History

from contextlib import asynccontextmanager
from fastapi import FastAPI
from server.services import tasker
from src.services.mcp_service import init_mcp_servers
from src.utils import logger
@asynccontextmanager
async def lifespan(app: FastAPI):
"""FastAPI lifespan事件管理器"""
# 初始化 MCP 服务器配置
try:
await init_mcp_servers()
except Exception as e:
logger.error(f"Failed to initialize MCP servers during startup: {e}")
2026-01-14 00:47:26 +08:00
await tasker.start()
yield
await tasker.shutdown()