"""Liveness and readiness endpoints. - ``/health`` — liveness: the process is up. No dependencies touched. - ``/health/ready`` — readiness: dependencies (Postgres) are reachable. Orchestrators and Caddy probe these; they are intentionally outside the versioned ``/api`` surface. """ from fastapi import APIRouter, Response, status from sqlalchemy import text from app.core.config import get_settings from app.core.db import get_engine router = APIRouter(tags=["health"]) @router.get("/health") async def health() -> dict: settings = get_settings() return { "status": "ok", "service": settings.app_name, "version": settings.version, "env": settings.app_env, } @router.get("/health/ready") async def ready(response: Response) -> dict: checks: dict[str, str] = {} try: async with get_engine().connect() as conn: await conn.execute(text("SELECT 1")) checks["database"] = "ok" return {"status": "ready", "checks": checks} except Exception as exc: # noqa: BLE001 — surface any failure as "not ready" checks["database"] = "error" response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE return {"status": "not ready", "checks": checks, "detail": str(exc)}