fix(api): await Kafka acknowledgements and bound HTTP requests

This commit is contained in:
2026-09-19 21:30:27 +03:30
parent 178741590e
commit 33593609e3
7 changed files with 447 additions and 406 deletions

View File

@@ -28,6 +28,8 @@ def build_dlq_envelope(
"""
Constructs a standardized DLQ envelope according to specification.
"""
if failure_reason not in ALLOWED_FAILURE_REASONS:
raise ValueError(f"Unsupported DLQ reason: {failure_reason}")
return {
"original_payload": original_payload,
"failure_reason": failure_reason,
@@ -56,11 +58,13 @@ def route_to_dlq(
)
envelope_bytes = json.dumps(envelope, default=str).encode("utf-8")
success = producer.produce(topic=topic, key=raw_id, value=envelope_bytes)
producer.produce(topic=topic, key=raw_id, value=envelope_bytes).result(
timeout=config.kafka.delivery_timeout_seconds + 1
)
worker_metrics.record_dlq(failure_reason, 1)
logger.warning(
f"Record routed to DLQ: reason={failure_reason}, field={failed_field}",
extra={"raw_id": raw_id, "event": "routed_to_dlq"},
)
return success
return True