@@ -14,8 +14,9 @@ class JobStatus:
1414 IN_PROGRESS = 'in_progress'
1515 COMPLETED = 'completed'
1616 FAILED = 'failed'
17+ CANCELLED = 'cancelled'
1718
18- ALL = [PENDING , IN_PROGRESS , COMPLETED , FAILED ]
19+ ALL = [PENDING , IN_PROGRESS , COMPLETED , FAILED , CANCELLED ]
1920
2021
2122# Media types that can be previewed in the frontend
@@ -94,19 +95,15 @@ def normalize_history_item(prompt_id: str, history_item: dict, include_outputs:
9495
9596 status_info = history_item .get ('status' , {})
9697 status_str = status_info .get ('status_str' ) if status_info else None
97- if status_str == 'success' :
98- status = JobStatus .COMPLETED
99- elif status_str == 'error' :
100- status = JobStatus .FAILED
101- else :
102- status = JobStatus .COMPLETED
10398
10499 outputs = history_item .get ('outputs' , {})
105100 outputs_count , preview_output = get_outputs_summary (outputs )
106101
102+ # Parse messages first to detect interruption before determining status
107103 execution_error = None
108104 execution_start_time = None
109105 execution_end_time = None
106+ was_interrupted = False
110107 if status_info :
111108 messages = status_info .get ('messages' , [])
112109 for entry in messages :
@@ -119,6 +116,16 @@ def normalize_history_item(prompt_id: str, history_item: dict, include_outputs:
119116 execution_end_time = event_data .get ('timestamp' )
120117 if event_name == 'execution_error' :
121118 execution_error = event_data
119+ elif event_name == 'execution_interrupted' :
120+ was_interrupted = True
121+
122+ # Determine status based on status_str and whether job was interrupted
123+ if status_str == 'success' :
124+ status = JobStatus .COMPLETED
125+ elif status_str == 'error' :
126+ status = JobStatus .CANCELLED if was_interrupted else JobStatus .FAILED
127+ else :
128+ status = JobStatus .COMPLETED
122129
123130 job = prune_dict ({
124131 'id' : prompt_id ,
@@ -268,13 +275,19 @@ def get_all_jobs(
268275 for item in queued :
269276 jobs .append (normalize_queue_item (item , JobStatus .PENDING ))
270277
278+ # History items can be completed, failed, or cancelled
279+ # We need to normalize first to determine the actual status
271280 include_completed = JobStatus .COMPLETED in status_filter
272281 include_failed = JobStatus .FAILED in status_filter
273- if include_completed or include_failed :
282+ include_cancelled = JobStatus .CANCELLED in status_filter
283+ if include_completed or include_failed or include_cancelled :
274284 for prompt_id , history_item in history .items ():
275- is_failed = history_item .get ('status' , {}).get ('status_str' ) == 'error'
276- if (is_failed and include_failed ) or (not is_failed and include_completed ):
277- jobs .append (normalize_history_item (prompt_id , history_item ))
285+ job = normalize_history_item (prompt_id , history_item )
286+ job_status = job .get ('status' )
287+ if ((job_status == JobStatus .COMPLETED and include_completed ) or
288+ (job_status == JobStatus .FAILED and include_failed ) or
289+ (job_status == JobStatus .CANCELLED and include_cancelled )):
290+ jobs .append (job )
278291
279292 if workflow_id :
280293 jobs = [j for j in jobs if j .get ('workflow_id' ) == workflow_id ]
0 commit comments