add level 5

This commit is contained in:
Матвей
2026-10-26 10:36:01 +03:00
parent ff33b8a7c2
commit 4f6e69cfac
8 changed files with 214 additions and 21 deletions
+12
View File
@@ -346,6 +346,18 @@ class PostgresStore:
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
return dict(row)
async def ensure_attachment_queue_capacity(self, connection: asyncpg.Connection, maximum: int) -> None:
"""Globally serialize admission so replicas cannot over-accept queued work."""
try:
await connection.execute("SELECT pg_advisory_xact_lock(41005, 1)")
pending = await connection.fetchval(
"SELECT count(*) FROM attachment_jobs WHERE status IN ('queued', 'processing')"
)
except DB_ERRORS as error:
raise ApiError(503, "unavailable", "PostgreSQL недоступен") from error
if pending >= maximum:
raise ApiError(429, "rate_limited", "Очередь обработки заполнена")
async def attachment_for_member(self, attachment_id: UUID, user_id: UUID) -> dict:
try:
row = await self.pool.fetchrow(