@@ -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,14 @@ 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
107102 execution_error = None
108103 execution_start_time = None
109104 execution_end_time = None
105+ was_interrupted = False
110106 if status_info :
111107 messages = status_info .get ('messages' , [])
112108 for entry in messages :
@@ -119,6 +115,15 @@ def normalize_history_item(prompt_id: str, history_item: dict, include_outputs:
119115 execution_end_time = event_data .get ('timestamp' )
120116 if event_name == 'execution_error' :
121117 execution_error = event_data
118+ elif event_name == 'execution_interrupted' :
119+ was_interrupted = True
120+
121+ if status_str == 'success' :
122+ status = JobStatus .COMPLETED
123+ elif status_str == 'error' :
124+ status = JobStatus .CANCELLED if was_interrupted else JobStatus .FAILED
125+ else :
126+ status = JobStatus .COMPLETED
122127
123128 job = prune_dict ({
124129 'id' : prompt_id ,
@@ -268,13 +273,13 @@ def get_all_jobs(
268273 for item in queued :
269274 jobs .append (normalize_queue_item (item , JobStatus .PENDING ))
270275
271- include_completed = JobStatus .COMPLETED in status_filter
272- include_failed = JobStatus . FAILED in status_filter
273- if include_completed or include_failed :
276+ history_statuses = { JobStatus .COMPLETED , JobStatus . FAILED , JobStatus . CANCELLED }
277+ requested_history_statuses = history_statuses & set ( status_filter )
278+ if requested_history_statuses :
274279 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 ) )
280+ job = normalize_history_item ( prompt_id , history_item )
281+ if job . get ( 'status' ) in requested_history_statuses :
282+ jobs .append (job )
278283
279284 if workflow_id :
280285 jobs = [j for j in jobs if j .get ('workflow_id' ) == workflow_id ]
0 commit comments