Handle the input style
Browse files
worker.py
CHANGED
@@ -87,23 +87,32 @@ class RabbitMQWorker:
|
|
87 |
if headers.get("request_type") == "process_files":
|
88 |
ch.basic_ack(delivery_tag=method.delivery_tag)
|
89 |
contexts = []
|
|
|
90 |
body_dict = json.loads(body)
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
|
|
94 |
try:
|
95 |
-
|
96 |
-
|
|
|
|
|
97 |
contexts.append(context)
|
98 |
except Exception as e:
|
99 |
-
|
100 |
-
|
|
|
101 |
|
102 |
-
|
|
|
|
|
103 |
|
104 |
headers["request_type"] = "question_extraction_update_from_gpu_server"
|
105 |
|
106 |
-
|
107 |
# Publish results
|
108 |
if self.publish_message(body_dict, headers):
|
109 |
logger.info("[Worker %s] Successfully published results to ml_server.", thread_id)
|
|
|
87 |
if headers.get("request_type") == "process_files":
|
88 |
ch.basic_ack(delivery_tag=method.delivery_tag)
|
89 |
contexts = []
|
90 |
+
|
91 |
body_dict = json.loads(body)
|
92 |
+
|
93 |
+
data = body_dict.get("data", {})
|
94 |
+
input_files = data.get("input_files", [])
|
95 |
|
96 |
+
logger.info("[Worker %s] Found %d file(s) to process.", thread_id, len(input_files))
|
97 |
+
|
98 |
+
for files in input_files:
|
99 |
try:
|
100 |
+
context = {
|
101 |
+
"key": files["key"],
|
102 |
+
"body": self.processor.process(files["url"], files["key"])
|
103 |
+
}
|
104 |
contexts.append(context)
|
105 |
except Exception as e:
|
106 |
+
err_str = f"Error processing file {files.get('key', '')}: {e}"
|
107 |
+
logger.error(err_str)
|
108 |
+
contexts.append({"key": files.get("key", ""), "body": err_str})
|
109 |
|
110 |
+
|
111 |
+
data["md_context"] = contexts
|
112 |
+
# topics = data.get("topics", [])
|
113 |
|
114 |
headers["request_type"] = "question_extraction_update_from_gpu_server"
|
115 |
|
|
|
116 |
# Publish results
|
117 |
if self.publish_message(body_dict, headers):
|
118 |
logger.info("[Worker %s] Successfully published results to ml_server.", thread_id)
|