Files
mtusi2026lab3/app/schemas/messages_schemas.py
T
vest1ter cde3374d8a ЛР3: балансировка HAProxy, 2 реплики API, идемпотентность, отказоустойчивость (на 4)
- X-Instance-Id в каждом ответе; обязательный Idempotency-Key, таблица idempotency_keys
  (миграция 0002, одна транзакция, конкурентные повторы через уникальный индекс)
- graceful shutdown: SIGTERM -> ready=503 -> drain 3 с -> закрытие порта
- compose: lb (HAProxy) + api x2 без портов + разовый migrate + postgres, лимиты CPU/RAM
- хуки stop-one/restart/restore-replicas, scripts/experiments.py (failover, idempotency, rolling)
- свои тесты: 44 (13 новых); evidence: smoke, pytest, persistence, failover, эксперименты
2026-10-29 10:58:17 +03:00

34 lines
806 B
Python

from uuid import UUID
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from utils.dates import UtcDatetime
class CreateMessageRequest(BaseModel):
# extra="forbid": клиент не может прислать sender_id.
model_config = ConfigDict(extra="forbid")
text: StrictStr = Field(min_length=1, max_length=4000)
@field_validator("text")
def validate_text(cls, v):
if not v.strip():
raise ValueError("text must not be blank")
return v
class MessageResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: UUID
chat_id: UUID
sender_id: UUID
text: str
created_at: UtcDatetime
class MessagePageResponse(BaseModel):
items: list[MessageResponse]
next_cursor: str | None