From 50aa24023d92a8c848df192ae2b201c958c5c673 Mon Sep 17 00:00:00 2001 From: Ben Copeland Date: Thu, 23 Mar 2017 11:39:44 +0000 Subject: S3: retry logic Based on Andy Doan's patch, this allows a retry to happen on the temp url. Because we used signed urls with S3, this patch will request a new signed url and try again. Change-Id: I32595f73ce0d85b8dcc69e71f030deaa223d61d0 --- linaro-cp.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/linaro-cp.py b/linaro-cp.py index e4dbf2c..2fcb297 100755 --- a/linaro-cp.py +++ b/linaro-cp.py @@ -107,7 +107,7 @@ class API_v1(object): def upload(self, src, dst, options): transfer_queue = self.get_transfer_queue(src, dst, options) if not transfer_queue: - print "Warning: no files to publish" + print("Warning: no files to publish") if options.verbose: pprint.pprint(transfer_queue) if not options.dry_run: @@ -160,11 +160,22 @@ class API_v3(API_v1): if not mtype: mtype = 'other' - resp = self._upload_data(url, data={'Content-Type': mtype}, headers={'AuthToken': self.api_key}) + data = {'Content-Type': mtype} + headers = {'AuthToken': self.api_key} - # now find the tempurl and really publish - location = resp.headers['location'] - self._put_s3(location, filename, mtype) + error = None + for x in range(3): + try: + # get the tempurl + resp = self._upload_data(url, data=data, headers=headers) + location = resp.headers['location'] + # publish file + self._put_s3(location, filename, mtype) + return + except Exception as e: + time.sleep(3) + error = e + raise error def link_latest(self, dst): url = self.server + '/api/v3/link_latest/' + dst -- cgit v1.2.3