Files
mtusi2026lab2/app/routes/health.py
T
Ильяс 9ddb2244bc
Skeleton contracts / contracts (pull_request) Canceled after 0s
feat: ЛР2 - PostgreSQL, Redis сессии и keyset-пагинация
2026-10-23 12:45:58 +03:00

32 lines
1.0 KiB
Python

from __future__ import annotations
from fastapi import APIRouter, status
from starlette.exceptions import HTTPException as StarletteHTTPException
from app.schemas import HealthResponse
from app.storage import storage
router = APIRouter(tags=["health"])
@router.get(
"/health/live", response_model=HealthResponse, status_code=status.HTTP_200_OK
)
async def health_live() -> HealthResponse:
"""Проверка жизни процесса (Liveness)."""
return HealthResponse(status="ok")
@router.get(
"/health/ready", response_model=HealthResponse, status_code=status.HTTP_200_OK
)
async def health_ready() -> HealthResponse:
"""Проверка готовности сервиса и его зависимостей (Readiness)."""
is_ready = await storage.check_health()
if not is_ready:
raise StarletteHTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="Сервис или его хранилища недоступны",
)
return HealthResponse(status="ok")