sync: handle exceptions

I.e. if network is gone for some reason, report that we're
able to sync some targets instead of just throwing exceptions
about broken pipe or something.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2017-07-03 02:12:54 +03:00
parent 3e0b148c44
commit 27bf57f415
2 changed files with 21 additions and 4 deletions
+14 -2
View File
@@ -246,8 +246,14 @@ class DataCloudAWS(DataCloudBase):
return
Logger.info('Downloading cache file from S3 "{}/{}"'.format(bucket.name, key_name))
key.get_contents_to_filename(item.resolved_cache.relative,
try:
key.get_contents_to_filename(item.resolved_cache.relative,
cb=create_cb(item.resolved_cache.relative))
except Exception as exc:
Logger.error('Failed to download "{}": {}'.format(key_name, exc))
return
progress.finish_target(os.path.basename(item.resolved_cache.relative))
Logger.info('Downloading completed')
@@ -269,8 +275,14 @@ class DataCloudAWS(DataCloudBase):
Logger.debug('Checksum miss-match. Re-uploading is required.')
key = bucket.new_key(aws_key)
key.set_contents_from_filename(data_item.resolved_cache.relative,
try:
key.set_contents_from_filename(data_item.resolved_cache.relative,
cb=create_cb(data_item.resolved_cache.relative))
except Exception as exc:
Logger.error('Failed to upload "{}": {}'.format(data_item.resolved_cache.relative, exc))
return
progress.finish_target(os.path.basename(data_item.resolved_cache.relative))
def remove_from_cloud(self, data_item):
+7 -2
View File
@@ -64,5 +64,10 @@ def map_progress(func, targets, n_threads):
"""
progress.set_n_total(len(targets))
p = ThreadPool(processes=n_threads)
p.map(func, targets)
progress.finish()
try:
p.map(func, targets)
except Exception as exc:
Logger.error('Unexpected exception while processing targets: {}'.format(exc))
finally:
progress.finish()