7455d7e426
130 issues auto-fixed (import ordering, UP045/UP006 type annotations), 33 issues manually fixed (E712/E501/E402/E722 + N818 rename + per-file wechat ignore for N8xx naming conventions). All 33 tests pass.
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
|
|
from app.api.router import api_router
|
|
from app.config import settings
|
|
|
|
engine = create_async_engine(settings.database_url, echo=settings.debug)
|
|
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
async def get_db() -> AsyncSession:
|
|
async with async_session() as session:
|
|
yield session
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logging.basicConfig(
|
|
level=getattr(logging, settings.log_level),
|
|
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
)
|
|
from app.scheduler.jobs import shutdown_scheduler, start_scheduler
|
|
start_scheduler()
|
|
yield
|
|
shutdown_scheduler()
|
|
await engine.dispose()
|
|
|
|
|
|
app = FastAPI(
|
|
title="广西政府采购网公告监控系统",
|
|
version="2.0.0",
|
|
lifespan=lifespan,
|
|
docs_url="/docs" if settings.debug else None,
|
|
redoc_url=None,
|
|
)
|
|
|
|
app.include_router(api_router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|