2025-10-23 14:08:08 +08:00
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
from server.services import tasker
|
|
|
|
|
|
2025-10-24 00:11:52 +08:00
|
|
|
# TODO:[已完成]使用lifespan进行统一生命周期管理
|
|
|
|
|
|
2025-10-23 14:08:08 +08:00
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
|
await tasker.start()
|
|
|
|
|
"""FastAPI lifespan事件管理器"""
|
|
|
|
|
yield
|
|
|
|
|
await tasker.shutdown()
|