Files
Aurora-Core/app/api/v1/health.py
T

37 lines
1.1 KiB
Python
Raw Normal View History

2026-09-04 17:34:03 -05:00
"""Liveness and readiness endpoints (section 24)."""
from __future__ import annotations
from fastapi import APIRouter
from app.core.config import get_settings
from app.core.database import database_is_ready
from app.core.redis import redis_is_ready
from app.schemas.health import DependencyStatus, HealthOut, ReadyOut
router = APIRouter(tags=["health"])
@router.get("/health", response_model=HealthOut)
async def health() -> HealthOut:
"""Liveness probe: process is up and able to respond. No dependency
checks — that's /ready."""
return HealthOut(status="ok")
@router.get("/ready", response_model=ReadyOut)
async def ready() -> ReadyOut:
settings = get_settings()
db_ok = await database_is_ready()
redis_ok = await redis_is_ready()
dependencies = [
DependencyStatus(name="postgresql", ok=db_ok, required=True),
DependencyStatus(name="redis", ok=redis_ok, required=settings.REDIS_REQUIRED),
]
is_ready = db_ok and (redis_ok or not settings.REDIS_REQUIRED)
return ReadyOut(status="ready" if is_ready else "not_ready", dependencies=dependencies)