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:
2026-10-31 06:48:20 +03:00
co-authored by Claude Opus 5.5
parent 40c709a78b
commit ff1a83b6ff
107 changed files with 9765 additions and 993 deletions
+68
View File
@@ -267,6 +267,74 @@ def jpeg_empty_scan(data: bytes | None = None) -> bytes:
return data[: _jpeg_header(data)[-1][2]] + JPEG_EOI
def jpeg_precision_12() -> bytes:
"""JPEG с 12 битами на компоненту в SOF: структура верна, а Pillow такой
не декодирует (спек `attachment-processing`, «Изображение не
декодируется»)."""
data = bytearray(jpeg())
sof = data.index(b"\xff\xc0")
data[sof + 4] = 12
return bytes(data)
def jpeg_halves(
orientation: int | None = None,
size: tuple[int, int] = (400, 200),
) -> bytes:
"""JPEG: левая половина красная, правая синяя; EXIF orientation —
необязательно."""
from PIL import Image # noqa: PLC0415
width, height = size
image = Image.new("RGB", size, (255, 0, 0))
image.paste((0, 0, 255), (width // 2, 0, width, height))
save: dict[str, object] = {"quality": 95}
if orientation is not None:
exif = Image.Exif()
exif[0x0112] = orientation
save["exif"] = exif
buffer = io.BytesIO()
image.save(buffer, "JPEG", **save)
return buffer.getvalue()
def png_half_transparent(size: tuple[int, int] = (200, 100)) -> bytes:
"""PNG RGBA: левая половина чёрная и непрозрачная, правая прозрачная."""
from PIL import Image # noqa: PLC0415
width, height = size
image = Image.new("RGBA", size, (0, 0, 0, 255))
image.paste((0, 0, 0, 0), (width // 2, 0, width, height))
buffer = io.BytesIO()
image.save(buffer, "PNG")
return buffer.getvalue()
def png_palette_transparent(size: tuple[int, int] = (200, 100)) -> bytes:
"""PNG с палитрой и tRNS: левая половина — чёрный цвет палитры, правая —
прозрачный."""
from PIL import Image # noqa: PLC0415
width, height = size
image = Image.new("P", size, 0)
image.putpalette([0, 0, 0, 0, 0, 0])
image.paste(1, (width // 2, 0, width, height))
buffer = io.BytesIO()
image.save(buffer, "PNG", transparency=bytes((255, 0)))
return buffer.getvalue()
def png_rgba_large(width: int = 8000, height: int = 5000) -> bytes:
"""PNG RGBA на 40 млн пикселей: пик памяти декодирования — как у
настоящего, файл мал и собирается быстро."""
from PIL import Image # noqa: PLC0415
image = Image.new("RGBA", (width, height), (10, 20, 30, 128))
buffer = io.BytesIO()
image.save(buffer, "PNG", compress_level=1)
return buffer.getvalue()
def png_variants() -> dict[str, bytes]:
"""Разновидности PNG спека: палитра, альфа, серый с альфой, 16 и 1
бит, Adam7."""