@@ -133,7 +133,10 @@ def submit(
133133 while any (
134134 job .status in ["waiting" , "running" ]
135135 for job in self ._client .list_jobs (session_id = batch_id )
136- ):
136+ ) and self ._client .get_session (session_id = batch_id ).status in [
137+ "starting" ,
138+ "running" ,
139+ ]:
137140 time .sleep (_DEFAULT_FETCH_INTERVAL )
138141
139142 if not open :
@@ -162,7 +165,7 @@ def _get_job_result_data(self, job_result: QaaSJobResult) -> str:
162165 if url is not None :
163166 return self ._get_data (url )
164167 else :
165- raise Exception ("Got result with empty data and url fields" )
168+ raise RuntimeError ("Got result with empty data and url fields" )
166169 else :
167170 return result
168171
@@ -260,16 +263,25 @@ def _query_job_progress(
260263
261264 def _get_batch_status (self , batch_id : str ) -> BatchStatus :
262265 """Gets the status of a batch from its ID."""
266+ jobs = self ._client .list_jobs (session_id = batch_id )
267+
268+ error_in_jobs = any (
269+ job .status in ["cancelled" , "cancelling" , "error" ] for job in jobs
270+ )
271+
272+ if error_in_jobs :
273+ return BatchStatus .ERROR
274+
263275 session = self ._client .get_session (session_id = batch_id )
264276
265- status_mapping = {
277+ session_status_mapping = {
266278 "starting" : BatchStatus .PENDING ,
267279 "running" : BatchStatus .RUNNING ,
268280 "stopping" : BatchStatus .DONE ,
269281 "stopped" : BatchStatus .DONE ,
270282 }
271283
272- return status_mapping .get (session .status , BatchStatus .ERROR )
284+ return session_status_mapping .get (session .status , BatchStatus .ERROR )
273285
274286 def _get_job_ids (self , batch_id : str ) -> List [str ]:
275287 """Gets all the job IDs within a batch."""
0 commit comments