refactor async calls
This commit is contained in:
parent
e5a75b41a2
commit
2ce541d211
1 changed files with 18 additions and 20 deletions
|
@ -596,21 +596,13 @@ class Client(object):
|
|||
post['files'] = files['files']
|
||||
post['volume'] = name
|
||||
print 'sending list of files in %s (%s total)' % (name, len(post['files']))
|
||||
r = self.api.async('update', post)
|
||||
#send empty list to get updated list of requested info/files/data
|
||||
post = {'info': {}}
|
||||
r = self.api.update(post)
|
||||
if r['status']['code'] == 200:
|
||||
#backend works on update request asyncronously, wait for it to finish
|
||||
if 'taskId' in r['data']:
|
||||
t = self.api.taskStatus(task_id=r['data']['taskId'])
|
||||
print 'waiting for server ...'
|
||||
while t['data']['status'] == 'PENDING':
|
||||
time.sleep(5)
|
||||
t = self.api.taskStatus(task_id=r['data']['taskId'])
|
||||
#send empty list to get updated list of requested info/files/data
|
||||
post = {'info': {}}
|
||||
r = self.api.update(post)
|
||||
|
||||
if r['data']['info']:
|
||||
r = self.update_info(r['data']['info'], prefix)
|
||||
if r['data']['info']:
|
||||
r = self.update_info(r['data']['info'], prefix)
|
||||
|
||||
if not 'data' in r:
|
||||
print r
|
||||
|
@ -718,13 +710,7 @@ class Client(object):
|
|||
print 'sending info for %d files' % len(info)
|
||||
post = {'info': {}, 'upload': True}
|
||||
post['info'] = self.get_info_for_ids(info, prefix)
|
||||
r = self.api.update(post)
|
||||
if 'taskId' in r['data']:
|
||||
t = self.api.taskStatus(task_id=r['data']['taskId'])
|
||||
print 'waiting for server ...'
|
||||
while t['data']['status'] == 'PENDING':
|
||||
time.sleep(5)
|
||||
t = self.api.taskStatus(task_id=r['data']['taskId'])
|
||||
r = self.api.async('update', post)
|
||||
#send empty list to get updated list of requested info/files/data
|
||||
post = {'info': {}}
|
||||
r = self.api.update(post)
|
||||
|
@ -908,6 +894,18 @@ class API(ox.API):
|
|||
netloc = urlparse(self.url).netloc
|
||||
self._resume_file = '/tmp/pandora_client.%s.%s.json' % (os.environ.get('USER'), netloc)
|
||||
|
||||
def async(self, action, data, interval=5):
|
||||
t = r = getattr(self, action)(data)
|
||||
if r['status']['code'] == 200:
|
||||
# wait for async task to finish
|
||||
if 'taskId' in r['data']:
|
||||
t = self.taskStatus(task_id=r['data']['taskId'])
|
||||
print 'waiting for server ...'
|
||||
while t['data'].get('status') == 'PENDING':
|
||||
time.sleep(interval)
|
||||
t = self.taskStatus(task_id=r['data']['taskId'])
|
||||
return t
|
||||
|
||||
def uploadFrames(self, i, data):
|
||||
#upload frames
|
||||
if self.site['media'].get('importFrames') and i['frames']:
|
||||
|
|
Loading…
Reference in a new issue