Preserve distributed job context and expose grade 4 operational signals

This commit is contained in:
Artyom
2026-11-06 12:57:10 +03:00
parent 1a171d0d0f
commit 44d81fd80e
32 changed files with 1098 additions and 35 deletions
@@ -5,6 +5,7 @@ from pamqp.commands import Basic
from messenger.attachments.domain.jobs import JOB_TYPE
from messenger.shared.application.errors import Unavailable
from messenger.shared.infrastructure.trace_context import restored_context
EXCHANGE = RabbitExchange("attachments", declare=False)
QUEUE = "attachments.process"
@@ -18,19 +19,22 @@ class RabbitJobPublisher:
self._broker = broker
self._timeout = timeout
async def publish(self, job_id: UUID, body: bytes) -> None:
async def publish(
self, job_id: UUID, body: bytes, trace_context: dict[str, str] | None = None
) -> 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,
)
with restored_context(trace_context):
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):