forked from mtusi2026/mtusi2026lab5
add level 5
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user