two api-replicas with LB-nginx

This commit is contained in:
2026-11-04 17:20:59 +03:00
parent f20b751207
commit 5c191c3bc5
50 changed files with 2991 additions and 311 deletions
+12 -6
View File
@@ -1,3 +1,5 @@
import asyncio
from fastapi import APIRouter, Request
from app.core.database import check_database
@@ -15,12 +17,16 @@ async def liveness() -> Health:
@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):
if request.app.state.lifecycle.draining:
raise unavailable()
if not await check_redis(request.app.state.redis):
try:
async with asyncio.timeout(request.app.state.settings.readiness_timeout_seconds):
dependencies = await asyncio.gather(
check_database(request.app.state.engine),
check_redis(request.app.state.redis),
)
except TimeoutError:
raise unavailable() from None
if not all(dependencies):
raise unavailable()
return Health(status="ok")