28 lines
754 B
Python
28 lines
754 B
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import text
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from cpv3.db.session import get_db
|
|
|
|
router = APIRouter(prefix="/api", tags=["System"])
|
|
|
|
|
|
@router.get("/ping/")
|
|
async def ping() -> dict[str, str]:
|
|
return {"status": "ok"}
|
|
|
|
|
|
@router.get("/health/")
|
|
async def health(db: AsyncSession = Depends(get_db)) -> dict[str, str]:
|
|
"""Health check for Docker/K8s probes. Verifies DB connectivity."""
|
|
try:
|
|
await db.execute(text("SELECT 1"))
|
|
db_status = "connected"
|
|
except Exception:
|
|
db_status = "disconnected"
|
|
|
|
status = "ok" if db_status == "connected" else "degraded"
|
|
return {"status": status, "database": db_status}
|