20 lines
504 B
Python
20 lines
504 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
from sqlalchemy import text
|
|
|
|
from app.deps import DbSession
|
|
|
|
|
|
router = APIRouter(tags=["系统"])
|
|
|
|
|
|
@router.get("/health")
|
|
async def health(db: DbSession) -> dict[str, str]:
|
|
try:
|
|
await db.execute(text("select 1"))
|
|
except Exception as exc:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
|
detail="数据库不可用",
|
|
) from exc
|
|
return {"status": "ok", "database": "ok"}
|