@@ -102,65 +102,65 @@ async def process_task(task_data):
102102async def main ():
103103 """Main function - continuously read from stdin, process tasks, write to stdout."""
104104 logger .info ("Worker process started, waiting for tasks..." )
105-
105+
106106 try :
107107 # Continuously read and process tasks
108108 while True :
109109 try :
110110 # Read one line at a time
111111 line = sys .stdin .readline ()
112-
112+
113113 # Check for EOF
114114 if not line :
115115 logger .info ("EOF received, shutting down worker" )
116116 break
117-
117+
118118 # Parse the task
119119 task_data = json .loads (line .strip ())
120120 request_id = task_data .get ("request_id" , "unknown" )
121-
121+
122122 # Check for shutdown signal
123123 if task_data .get ("task_type" ) == "shutdown" :
124124 logger .info ("Shutdown signal received" )
125125 response = {"status" : "success" , "message" : "Shutting down" , "request_id" : request_id }
126126 print (json .dumps (response ), flush = True )
127127 break
128-
128+
129129 # Process the task
130130 response = await process_task (task_data )
131-
131+
132132 # Serialize response
133133 if response :
134134 serializable_response = response .model_dump (mode = "json" )
135135 else :
136136 serializable_response = {"status" : "success" }
137-
137+
138138 # Add request_id to response
139139 serializable_response ["request_id" ] = request_id
140-
140+
141141 # Send response back to parent (one line per response)
142142 print (json .dumps (serializable_response ), flush = True )
143-
143+
144144 except json .JSONDecodeError as e :
145145 error_response = {
146146 "status" : "error" ,
147147 "message" : f"Invalid JSON input: { str (e )} " ,
148- "request_id" : task_data .get ("request_id" , "unknown" ) if ' task_data' in locals () else "unknown"
148+ "request_id" : task_data .get ("request_id" , "unknown" ) if " task_data" in locals () else "unknown" ,
149149 }
150150 print (json .dumps (error_response ), flush = True )
151-
151+
152152 except Exception as e :
153153 logger .error ("Error processing task: %s" , str (e ))
154154 error_response = {
155155 "status" : "error" ,
156156 "message" : f"Unexpected error: { str (e )} " ,
157- "request_id" : task_data .get ("request_id" , "unknown" ) if ' task_data' in locals () else "unknown"
157+ "request_id" : task_data .get ("request_id" , "unknown" ) if " task_data" in locals () else "unknown" ,
158158 }
159159 print (json .dumps (error_response ), flush = True )
160-
160+
161161 except KeyboardInterrupt :
162162 logger .info ("Worker interrupted" )
163- except Exception as e :
163+ except Exception :
164164 logger .exception ("Fatal error in worker main loop" )
165165 finally :
166166 logger .info ("Worker process shutting down" )
0 commit comments