27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
from fastapi import APIRouter, Request
|
|
|
|
from app.core.database import check_database
|
|
from app.core.redis import check_redis
|
|
from app.errors.exceptions import unavailable
|
|
from app.schemas.base import Health
|
|
|
|
router = APIRouter(prefix="/health", tags=["health"])
|
|
|
|
|
|
@router.get("/live")
|
|
async def liveness() -> Health:
|
|
return Health(status="ok")
|
|
|
|
|
|
@router.get("/ready")
|
|
async def readiness(request: Request) -> Health:
|
|
# TODO(4.1): если реплика получила SIGTERM (lifecycle.draining) — сразу 503,
|
|
# чтобы LB исключил её до закрытия сокета.
|
|
# TODO(4.1): проверки зависимостей должны укладываться в timeout healthcheck;
|
|
# зафиксируйте в REPORT.md, какие зависимости критичны.
|
|
if not await check_database(request.app.state.engine):
|
|
raise unavailable()
|
|
if not await check_redis(request.app.state.redis):
|
|
raise unavailable()
|
|
return Health(status="ok")
|