Files
mtusi2026lab2/src/messenger/attachments/infrastructure/rabbitmq.py
T
ArtyomandClaude Opus 5.5 5ae3d77152 Carry over the lab 5 solution
Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6, RustFS and RabbitMQ configuration, migrations, hooks,
scenario scripts and the CI job from the lab 5 solution commit 64d5c67,
keep the lab 5 Makefile targets on top of the unchanged skeleton
targets, and append the lab 5 solution variables to the skeleton
.env.example. The package and the application follow the contract
version 1.6.0, and the image, the throwaway test containers and the
broker vhost description are tagged lab6 so they do not collide with a
lab 5 stand on the same host.

This is the starting point of the lab 6 cycle: lint, own tests and the
offline skeleton check pass before any lab 6 change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 03:51:58 +03:00

38 lines
1.3 KiB
Python

from uuid import UUID
from faststream.rabbit import RabbitBroker, RabbitExchange
from pamqp.commands import Basic
from messenger.attachments.domain.jobs import JOB_TYPE
from messenger.shared.application.errors import Unavailable
EXCHANGE = RabbitExchange("attachments", declare=False)
QUEUE = "attachments.process"
DEAD_LETTERS = "attachments.process.dlq"
class RabbitJobPublisher:
__slots__ = ("_broker", "_timeout")
def __init__(self, broker: RabbitBroker, timeout: float) -> None:
self._broker = broker
self._timeout = timeout
async def publish(self, job_id: UUID, body: bytes) -> None:
try:
confirmation = await self._broker.publish(
body,
exchange=EXCHANGE,
routing_key=JOB_TYPE,
mandatory=True,
persist=True,
message_id=str(job_id),
message_type=JOB_TYPE,
content_type="application/json",
timeout=self._timeout,
)
except Exception as error:
raise Unavailable("брокер не принял задание") from error
if not isinstance(confirmation, Basic.Ack):
raise Unavailable("брокер не подтвердил задание")