feat: перенос логики с 4лабф

This commit is contained in:
Enterxx2
2026-11-09 22:33:50 +03:00
parent 276dbdad8a
commit 1d8dfb7ea4
166 changed files with 13171 additions and 6 deletions
+49
View File
@@ -0,0 +1,49 @@
from fastapi import APIRouter, Depends, Request, status
from domain import HealthSchema
from domain.errors import UnavailableError
from infrastructure.dependencies import (
DatabasePoolManager,
ObjectStorageManager,
get_database,
get_storage,
)
health_router = APIRouter(prefix="/health", tags=["Health"])
@health_router.get(
"/live",
status_code=status.HTTP_200_OK,
response_model=HealthSchema,
)
async def liveness() -> HealthSchema:
"""Процесс жив и обрабатывает хттп"""
return HealthSchema()
@health_router.get(
"/ready",
status_code=status.HTTP_200_OK,
response_model=HealthSchema,
)
async def readiness(
request: Request,
database: DatabasePoolManager = Depends(get_database),
storage: ObjectStorageManager = Depends(get_storage),
) -> HealthSchema:
"""
Приложение не завершается, PostgreSQL и S3 отвечают: с lab4 загрузка
и скачивание вложений входят в обязательный синхронный путь.
Valkey не критичен: без него сессии читаются из PostgreSQL. Без S3
недоступны только вложения — nginx не исключает реплику по readiness,
поэтому сообщения продолжают работать, а реплика честно сообщает 503.
"""
if not getattr(request.app.state, "is_ready", False):
raise UnavailableError()
if not await database.check():
raise UnavailableError("бд недоступна")
if not await storage.check():
raise UnavailableError("хранилище файлов недоступно")
return HealthSchema()