feat: process attachments asynchronously with RabbitMQ and a worker
Upload answers 202 after staging, a queued job in PostgreSQL and a broker confirm; a separate worker publishes the original and a thumbnail with bounded retries. Adds the job and variant tables, the broker service, the worker S3 user, cleanup and reconcile support for staging and variants, the failure stand with broker and worker, bench and driver updates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Проверка ответов по `contracts/openapi.json` и форматам контракта."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Iterable, Mapping
|
||||
@@ -130,6 +131,16 @@ def assert_ok(resp: httpx.Response, status: int, schema: str) -> Any:
|
||||
return body
|
||||
|
||||
|
||||
def assert_accepted(resp: httpx.Response) -> dict[str, Any]:
|
||||
"""Принятая загрузка: 202 и снимок на момент приёма по схеме контракта
|
||||
(спек `student-tests`, «Готовность вложения в тестах»)."""
|
||||
attachment = assert_ok(resp, 202, "Attachment")
|
||||
assert attachment["status"] == "queued", describe(resp, "not queued")
|
||||
assert attachment["variants"] == [], describe(resp, "has variants")
|
||||
assert attachment["error_code"] is None, describe(resp, "has error_code")
|
||||
return attachment
|
||||
|
||||
|
||||
def assert_error(resp: httpx.Response, status: int) -> dict[str, Any]:
|
||||
"""Ошибка в формате контракта; `code` соответствует статусу."""
|
||||
assert resp.status_code == status, describe(resp, f"expected {status}")
|
||||
@@ -226,6 +237,37 @@ def assert_content(
|
||||
)
|
||||
|
||||
|
||||
def assert_variant_content(
|
||||
resp: httpx.Response,
|
||||
variant: Mapping[str, Any],
|
||||
) -> bytes:
|
||||
"""Байты варианта: те же заголовки, что у оригинала, размер и SHA-256 —
|
||||
поля варианта в метаданных. Возвращает байты."""
|
||||
check_body(dict(variant), "Variant")
|
||||
assert resp.status_code == 200, describe(resp, "expected 200")
|
||||
assert resp.headers.get("X-Request-Id", "").strip(), describe(
|
||||
resp,
|
||||
"no X-Request-Id",
|
||||
)
|
||||
assert_instance_id(resp)
|
||||
assert resp.headers.get("Content-Type") == variant["content_type"], (
|
||||
describe(resp, f"Content-Type is not {variant['content_type']}")
|
||||
)
|
||||
assert resp.headers.get("Content-Length") == str(variant["size_bytes"]), (
|
||||
describe(resp, f"Content-Length is not {variant['size_bytes']}")
|
||||
)
|
||||
assert resp.headers.get("X-Content-Type-Options") == "nosniff", describe(
|
||||
resp,
|
||||
"no X-Content-Type-Options: nosniff",
|
||||
)
|
||||
assert_no_storage_traces(resp)
|
||||
assert len(resp.content) == variant["size_bytes"], "size_bytes differs"
|
||||
assert hashlib.sha256(resp.content).hexdigest() == variant["sha256"], (
|
||||
"sha256 of variant differs"
|
||||
)
|
||||
return resp.content
|
||||
|
||||
|
||||
def assert_instance_id(resp: httpx.Response) -> str:
|
||||
"""Непустой `X-Instance-Id` допустимого формата; возвращает значение."""
|
||||
instance_id = resp.headers.get("X-Instance-Id", "")
|
||||
|
||||
Reference in New Issue
Block a user