SkyNait commited on
Commit
e9359a4
·
verified ·
1 Parent(s): bab6bde

Handle the input style

Browse files
Files changed (1) hide show
  1. worker.py +17 -8
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
- # Process files
93
- for file in body_dict.get("input_files", []):
 
94
  try:
95
- logger.info("[Worker %s] Processing %d input files.", thread_id, len(file))
96
- context = {"key": file["key"], "body": self.processor.process(file["url"], file["key"])}
 
 
97
  contexts.append(context)
98
  except Exception as e:
99
- print(f"Error processing file {file['key']}: {e}")
100
- contexts.append({"key": file["key"], "body": f"Error: {str(e)}"})
 
101
 
102
- body_dict["md_context"] = contexts
 
 
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)