Skip to content
This repository was archived by the owner on Mar 20, 2026. It is now read-only.

Commit 29bf45c

Browse files
committed
fix(shim): add required AMQP headers for station recognition
1 parent cecf2da commit 29bf45c

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

  • workers/document-source-shim

workers/document-source-shim/app.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import json
22
import os
3+
import socket
34
import sys
45
import time
6+
import uuid
7+
from datetime import datetime, timezone
8+
59
import pika
610

711

12+
INSTANCE_NAME = f"shim-document-source-{socket.gethostname()}"
13+
WORKER_NAME = "worker-document-source"
14+
15+
816
def get_env(name: str, default: str | None = None) -> str:
917
value = os.getenv(name, default)
1018
if value is None:
@@ -102,16 +110,29 @@ def handle(ch, method, properties, body):
102110
job["attributes"] = attrs
103111

104112
out_body = json.dumps(job).encode("utf-8")
113+
114+
# Build the headers the station expects
115+
trace_id = str(uuid.uuid4())
116+
ts = datetime.now(timezone.utc).isoformat()
117+
headers = {
118+
"x-kimi-worker-instance-name": INSTANCE_NAME,
119+
"x-kimi-worker-name": WORKER_NAME,
120+
"x-trace-id": trace_id,
121+
"timestamp": ts,
122+
}
123+
105124
channel.basic_publish(
106125
exchange=exchange,
107126
routing_key=publish_result_rk,
108127
body=out_body,
109128
properties=pika.BasicProperties(
110-
content_type="application/json", delivery_mode=2
129+
content_type="application/json",
130+
delivery_mode=2,
131+
headers=headers,
111132
),
112133
)
113134
print(
114-
f"[shim] Published result {publish_result_rk}: {job.get('filename')}",
135+
f"[shim] Published result {publish_result_rk}: {job.get('filename')} (trace={trace_id})",
115136
flush=True,
116137
)
117138
# Also kick pdf-metadata worker
@@ -120,7 +141,9 @@ def handle(ch, method, properties, body):
120141
routing_key=publish_pdfmeta_job_rk,
121142
body=out_body,
122143
properties=pika.BasicProperties(
123-
content_type="application/json", delivery_mode=2
144+
content_type="application/json",
145+
delivery_mode=2,
146+
headers=headers,
124147
),
125148
)
126149
print(
@@ -133,7 +156,9 @@ def handle(ch, method, properties, body):
133156
routing_key=publish_spec_html_job_rk,
134157
body=out_body,
135158
properties=pika.BasicProperties(
136-
content_type="application/json", delivery_mode=2
159+
content_type="application/json",
160+
delivery_mode=2,
161+
headers=headers,
137162
),
138163
)
139164
print(

0 commit comments

Comments
 (0)