File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -349,6 +349,21 @@ async def event_generator():
349349
350350 # Check for terminal status (completed, cancelled, failed)
351351 is_terminal = job .status == "completed" or job .status == "cancelled" or job .status .startswith ("failed" )
352+ if is_terminal :
353+ # Send final status event if it hasn't been sent already
354+ if current_data_json != last_data_sent :
355+ yield f"event: progress\n data: { current_data_json } \n \n "
356+ last_data_sent = current_data_json # Ensure last_data_sent is updated even for the final message
357+ print (f"Sent final progress update for job { job_id } : Status { job .status } " )
358+
359+ # Send a dedicated 'status' event to signal completion/failure/cancellation
360+ final_status_data = json .dumps ({"status" : job .status , "message" : "Job finished." })
361+ yield f"event: status\n data: { final_status_data } \n \n "
362+ print (f"Job { job_id } reached terminal state: { job .status } . Closing stream." )
363+ break # Exit loop after sending final status
364+
365+ # Wait before checking again only if not terminal
366+ await asyncio .sleep (1 ) # Check every 1 second
352367 if is_terminal :
353368 # Send final status event
354369 final_data = json .dumps ({"status" : job .status , "message" : "Job finished." })
You can’t perform that action at this time.
0 commit comments