forked from mtusi2026/mtusi2026lab2
feat: реализация второй лабы по тз
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from fastapi import APIRouter, Request, status
|
||||
from fastapi import APIRouter, Depends, Request, status
|
||||
|
||||
from domain import HealthSchema
|
||||
from domain.errors import UnavailableError
|
||||
from infrastructure.dependencies import DatabasePoolManager, get_database
|
||||
|
||||
health_router = APIRouter(prefix="/health", tags=["Health"])
|
||||
|
||||
@@ -21,8 +22,15 @@ async def liveness() -> HealthSchema:
|
||||
status_code=status.HTTP_200_OK,
|
||||
response_model=HealthSchema,
|
||||
)
|
||||
async def readiness(request: Request) -> HealthSchema:
|
||||
"""Хранилище создано и приложение не завершается"""
|
||||
async def readiness(
|
||||
request: Request, database: DatabasePoolManager = Depends(get_database)
|
||||
) -> HealthSchema:
|
||||
"""
|
||||
Приложение не завершается и PostgreSQL отвечает. Valkey не критичен:
|
||||
без него сессии читаются из PostgreSQL, поэтому он не влияет на готовность.
|
||||
"""
|
||||
if not getattr(request.app.state, "is_ready", False):
|
||||
raise UnavailableError()
|
||||
if not await database.check():
|
||||
raise UnavailableError("бд недоступна")
|
||||
return HealthSchema()
|
||||
|
||||
Reference in New Issue
Block a user