@@ -114,6 +114,19 @@ def filtered_logs(self, job_id: str, **kwargs) -> str:
114
114
class Job :
115
115
"""Job."""
116
116
117
+ PENDING = "PENDING"
118
+ RUNNING = "RUNNING"
119
+ STOPPED = "STOPPED"
120
+ SUCCEEDED = "SUCCEEDED"
121
+ FAILED = "FAILED"
122
+ QUEUED = "QUEUED"
123
+ # RUNNING statuses
124
+ MAPPING = "MAPPING"
125
+ OPTIMIZING_HARDWARE = "OPTIMIZING_HARDWARE"
126
+ WAITING_QPU = "WAITING_QPU"
127
+ EXECUTING_QPU = "EXECUTING_QPU"
128
+ POST_PROCESSING = "POST_PROCESSING"
129
+
117
130
def __init__ (
118
131
self ,
119
132
job_id : str ,
@@ -200,8 +213,8 @@ def result(self, wait=True, cadence=30, verbose=False, maxwait=0):
200
213
201
214
def in_terminal_state (self ) -> bool :
202
215
"""Checks if job is in terminal state"""
203
- terminal_states = ["CANCELED" , "DONE" , "ERROR" ]
204
- return self .status () in terminal_states
216
+ terminal_status = ["CANCELED" , "DONE" , "ERROR" ]
217
+ return self .status () in terminal_status
205
218
206
219
def __repr__ (self ):
207
220
return f"<Job | { self .job_id } >"
@@ -277,15 +290,55 @@ def save_result(result: Dict[str, Any]):
277
290
return response .ok
278
291
279
292
293
+ def update_status (status : str ):
294
+ """Update sub status."""
295
+
296
+ version = os .environ .get (ENV_GATEWAY_PROVIDER_VERSION )
297
+ if version is None :
298
+ version = GATEWAY_PROVIDER_VERSION_DEFAULT
299
+
300
+ token = os .environ .get (ENV_JOB_GATEWAY_TOKEN )
301
+ if token is None :
302
+ logging .warning (
303
+ "'sub_status' cannot be updated since"
304
+ "there is no information about the"
305
+ "authorization token in the environment."
306
+ )
307
+ return False
308
+
309
+ instance = os .environ .get (ENV_JOB_GATEWAY_INSTANCE , None )
310
+
311
+ url = (
312
+ f"{ os .environ .get (ENV_JOB_GATEWAY_HOST )} /"
313
+ f"api/{ version } /jobs/{ os .environ .get (ENV_JOB_ID_GATEWAY )} /sub_status/"
314
+ )
315
+ response = requests .patch (
316
+ url ,
317
+ data = {"sub_status" : status },
318
+ headers = get_headers (token = token , instance = instance ),
319
+ timeout = REQUESTS_TIMEOUT ,
320
+ )
321
+ if not response .ok :
322
+ sanitized = response .text .replace ("\n " , "" ).replace ("\r " , "" )
323
+ logging .warning ("Something went wrong: %s" , sanitized )
324
+
325
+ return response .ok
326
+
327
+
280
328
def _map_status_to_serverless (status : str ) -> str :
281
329
"""Map a status string from job client to the Qiskit terminology."""
282
330
status_map = {
283
- "PENDING" : "INITIALIZING" ,
284
- "RUNNING" : "RUNNING" ,
285
- "STOPPED" : "CANCELED" ,
286
- "SUCCEEDED" : "DONE" ,
287
- "FAILED" : "ERROR" ,
288
- "QUEUED" : "QUEUED" ,
331
+ Job .PENDING : "INITIALIZING" ,
332
+ Job .RUNNING : "RUNNING" ,
333
+ Job .STOPPED : "CANCELED" ,
334
+ Job .SUCCEEDED : "DONE" ,
335
+ Job .FAILED : "ERROR" ,
336
+ Job .QUEUED : "QUEUED" ,
337
+ Job .MAPPING : "RUNNING: MAPPING" ,
338
+ Job .OPTIMIZING_HARDWARE : "RUNNING: OPTIMIZING_FOR_HARDWARE" ,
339
+ Job .WAITING_QPU : "RUNNING: WAITING_FOR_QPU" ,
340
+ Job .EXECUTING_QPU : "RUNNING: EXECUTING_QPU" ,
341
+ Job .POST_PROCESSING : "RUNNING: POST_PROCESSING" ,
289
342
}
290
343
291
344
try :
0 commit comments