This commit is contained in:
2026-09-09 11:35:02 +08:00
parent bc1c72d558
commit d656c05b3d
35 changed files with 711 additions and 3194 deletions

View File

@@ -1,11 +1,12 @@
"""FastAPI 入口。数据库结构统一由 Alembic 管理。"""
from contextlib import asynccontextmanager
import asyncio
from contextlib import asynccontextmanager, suppress
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy import text
from . import cache
from . import cache, scheduler
from .api import router
from .auth_api import router as auth_router
from .config import settings
@@ -16,7 +17,11 @@ from .db import engine
async def lifespan(app: FastAPI):
async with engine.connect() as conn:
await conn.execute(text("SELECT 1"))
nightly = asyncio.create_task(scheduler.run_nightly_loop())
yield
nightly.cancel()
with suppress(asyncio.CancelledError):
await nightly
await engine.dispose()
await cache.aclose() # 释放 Redis 连接池(未启用时是 no-op