fix(rmbg): 将 on_event 迁移到 lifespan 事件处理器以消除弃用警告
This commit is contained in:
parent
0e1a99d975
commit
7f03cc24e3
@ -1,29 +1,30 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from settings import settings
|
||||
from api import router, service
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""应用生命周期管理"""
|
||||
# 启动时初始化
|
||||
if settings.enable_queue_batch:
|
||||
await service._start_queue_processor()
|
||||
yield
|
||||
# 关闭时清理资源
|
||||
await service.cleanup()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Remove Background",
|
||||
description="图片去背景",
|
||||
version="1.0.0"
|
||||
version="1.0.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
# 注册路由
|
||||
app.include_router(router)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""应用启动时初始化队列批处理机制"""
|
||||
if settings.enable_queue_batch:
|
||||
await service._start_queue_processor()
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
"""应用关闭时清理资源"""
|
||||
await service.cleanup()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user