fix(api): await Kafka acknowledgements and bound HTTP requests
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user