Реализовать стенд лабораторной 3: две API-реплики и балансировка

FastAPI + PostgreSQL как единый источник истины: пользователи, Basic/Bearer-сессии, чаты, сообщения. Сессии и идемпотентные ключи хранятся в БД, поэтому реплики взаимозаменяемы. Общая идемпотентность POST сообщения по Idempotency-Key, включая конкурентный повтор через разные реплики. compose.yaml: postgres, one-shot migrate, api1, api2 и nginx как единственная публичная точка входа. Добавлены scripts/stop-one.sh и scripts/restart.sh, student-tests, evidence и заполненный REPORT.md.
This commit is contained in:
drunkdiente
2026-11-07 16:04:29 +03:00
parent 0ab3a341aa
commit 3aba500a0e
51 changed files with 1629 additions and 22 deletions
+19
View File
@@ -0,0 +1,19 @@
"""Domain errors mapped to the contract error envelope."""
from __future__ import annotations
from typing import Mapping
class ApiError(Exception):
def __init__(
self,
status_code: int,
code: str,
message: str,
headers: Mapping[str, str] | None = None,
) -> None:
super().__init__(message)
self.status_code = status_code
self.code = code
self.message = message
self.headers = dict(headers or {})