2323app = FastAPI ()
2424
2525
26- # ✅ DB RETRY LOGIC
2726def init_db_with_retry (max_retries = 10 , delay = 3 ):
2827 for attempt in range (1 , max_retries + 1 ):
2928 try :
@@ -175,7 +174,6 @@ async def upload_file(file: UploadFile = File(...), db: Session = Depends(get_db
175174 db .refresh (record )
176175 record_id = record .id
177176
178- # ✅ REQUIRED LOG
179177 logger .info (
180178 '{"message": "DB record created", "id": %d, "filename": "%s"}' ,
181179 record_id ,
@@ -184,30 +182,15 @@ async def upload_file(file: UploadFile = File(...), db: Session = Depends(get_db
184182
185183 # Step 3 — temp write
186184 temp_path = write_to_temp (file_bytes , file .filename )
185+ logger .info ('{"message": "Write temp file", "path": "%s"}' , temp_path )
187186
188- # ✅ REQUIRED LOG
189- logger .info (
190- '{"message": "Write temp file", "path": "%s"}' ,
191- temp_path ,
192- )
193-
194- # Step 4 — ML
195- # ✅ REQUIRED LOG
196- logger .info (
197- '{"message": "ML stub invoked", "path": "%s"}' ,
198- temp_path ,
199- )
200-
187+ # Step 4 — ML stub + MinIO
188+ logger .info ('{"message": "ML stub invoked", "path": "%s"}' , temp_path )
201189 ml_result = run_ml (temp_path )
202190
203191 object_name = f"{ uuid .uuid4 ().hex } .{ ext } "
204192 minio_object = upload_to_minio (temp_path , object_name )
205-
206- # ✅ REQUIRED LOG
207- logger .info (
208- '{"message": "Upload to MinIO complete", "object": "%s"}' ,
209- minio_object ,
210- )
193+ logger .info ('{"message": "Upload to MinIO complete", "object": "%s"}' , minio_object )
211194
212195 update_status (
213196 db ,
@@ -216,22 +199,21 @@ async def upload_file(file: UploadFile = File(...), db: Session = Depends(get_db
216199 processed_at = datetime .utcnow (),
217200 )
218201
219- # Step 5 — trigger agents
202+ # Step 5 — delete temp then trigger agents with minio_object
203+ delete_from_temp (temp_path )
204+
220205 def _run_agents ():
221206 try :
222207 requests .post (
223208 "http://agents:8123/run" ,
224- json = {"record_id" : record_id , "file_path " : temp_path },
209+ json = {"record_id" : record_id , "minio_object " : minio_object },
225210 timeout = 120 ,
226211 )
227212 except Exception :
228213 logger .exception ('{"message": "Failed to trigger agents pipeline"}' )
229214
230215 threading .Thread (target = _run_agents , daemon = True ).start ()
231216
232- delete_from_temp (temp_path )
233-
234- # ✅ REQUIRED LOG
235217 logger .info (
236218 '{"message": "Upload pipeline complete", "id": %s, "filename": "%s"}' ,
237219 record_id ,
0 commit comments