|
@@ -1,10 +1,8 @@
|
|
|
import orthancInterface
|
|
|
import orthancDatabaseBrowser
|
|
|
import json
|
|
|
-
|
|
|
-
|
|
|
-def getJobId(jobDescription):
|
|
|
- return jobDescription['ID']
|
|
|
+import time
|
|
|
+import datetime
|
|
|
|
|
|
def getStatus(jobStatus):
|
|
|
return jobStatus['State']
|
|
@@ -31,7 +29,7 @@ class orthancPeers:
|
|
|
response=self.net.delete(apiUrl)
|
|
|
#empty response
|
|
|
|
|
|
- def sendResource(self,name,orthancId):
|
|
|
+ def createSendJob(self,name,orthancId):
|
|
|
#returns jobDescription as JSON (ID,Path)
|
|
|
apiUrl=self.net.getCoreURL()
|
|
|
apiUrl+=f'/peers/{name}/store'
|
|
@@ -41,7 +39,7 @@ class orthancPeers:
|
|
|
response=self.net.post(apiUrl,jsonData,'json')
|
|
|
return orthancDatabaseBrowser.extractJSON(response.data)
|
|
|
|
|
|
- def checkJobStatus(self,name,jobId):
|
|
|
+ def checkJobStatus(self,jobId):
|
|
|
#returns jobStatus as JSON (ErrorCode, ErrorDescription, ErrorDetails, Progress, State)
|
|
|
apiUrl=self.net.getCoreURL()
|
|
|
apiUrl+=f'/jobs/{jobId}'
|
|
@@ -61,4 +59,32 @@ class orthancPeers:
|
|
|
return orthancDatabaseBrowser.extractJSON(response.data)
|
|
|
|
|
|
|
|
|
+ def sendResource(self,name,orthancId):
|
|
|
+ jobDescription=self.createSendJob(name,orthancId)
|
|
|
+ jobId=jobDescription['ID']
|
|
|
+ self.monitorProgress(jobId)
|
|
|
+
|
|
|
+ def monitorProgress(self,jobId,tSleepGuess=10):
|
|
|
+ dateFormate='%Y%m%dT%H%M%S.%f'
|
|
|
+ tSleep=tSleepGuess
|
|
|
+ while True:
|
|
|
+#wait 10 s
|
|
|
+ time.sleep(tSleep)
|
|
|
+ jobStatus=self.checkJobStatus(jobId)
|
|
|
+ if jobStatus['State']=="Success":
|
|
|
+ return
|
|
|
+ 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=min(tSleep,tSleepGuess)
|
|
|
+ print('Working: {}/100, ETA: {} s, next check {} s'.format(jobStatus['Progress'],delta.seconds,tSleep))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|