two api-replicas with LB-nginx
This commit is contained in:
+12
-6
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user