|
@@ -0,0 +1,38 @@
|
|
|
+import orthancDatabaseBrowser
|
|
|
+import datetime
|
|
|
+import time
|
|
|
+
|
|
|
+
|
|
|
+def checkJobStatus(net,jobId):
|
|
|
+ #returns jobStatus as JSON (ErrorCode, ErrorDescription, ErrorDetails, Progress, State)
|
|
|
+ apiUrl='/'.join([net.getCoreURL(),'jobs',f'{jobId}'])
|
|
|
+ response=net.get(apiUrl)
|
|
|
+ return orthancDatabaseBrowser.extractJSON(response.data)
|
|
|
+
|
|
|
+def monitorProgress(net,jobId,tSleepGuess=10):
|
|
|
+ dateFormat='%Y%m%dT%H%M%S.%f'
|
|
|
+ tSleep=tSleepGuess
|
|
|
+ while True:
|
|
|
+#wait 10 s
|
|
|
+ time.sleep(tSleep)
|
|
|
+ jobStatus=checkJobStatus(net,jobId)
|
|
|
+ if jobStatus['State']=="Success":
|
|
|
+ print('Job succeeded')
|
|
|
+ return True
|
|
|
+ if jobStatus['State']=="Failure":
|
|
|
+ print('Job failed')
|
|
|
+ return False
|
|
|
+
|
|
|
+ try:
|
|
|
+ eta=datetime.datetime.strptime(jobStatus['EstimatedTimeOfArrival'],dateFormat)
|
|
|
+ except KeyError:
|
|
|
+ continue
|
|
|
+ t0=datetime.datetime.strptime(jobStatus['Timestamp'],dateFormat)
|
|
|
+ delta=eta-t0
|
|
|
+ tSleep=0.05*delta.seconds
|
|
|
+ tSleep=max(tSleep,tSleepGuess)
|
|
|
+ print('Working: {}/100, ETA: {} s, next check {} s'.format(jobStatus['Progress'],delta.seconds,tSleep))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|