summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-07-20 12:18:29 -0500
committerAndy Doan <andy.doan@linaro.org>2016-07-20 12:18:29 -0500
commitfa6a3dd8367fdfd6e7fb8a2d1eabf303e22a510f (patch)
tree9d1f2ee8b452fe227233953e2704a34ff740fdea
parent9bed019b882c5c2b41777c44f50ab0eaa7aa095a (diff)
add retry logic for put_s3
Forgot to do that in the last commit. Change-Id: I09771698f34a785108dc3ee0659d8659831b64ae
-rwxr-xr-xlinaro-cp.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/linaro-cp.py b/linaro-cp.py
index 9dfa919..43f9aaa 100755
--- a/linaro-cp.py
+++ b/linaro-cp.py
@@ -158,7 +158,7 @@ class API_v3(API_v1):
return super(API_v3, self)._upload_data(
url, data, headers, retry_count)
- def _put_s3(self, url, filename, mtype):
+ def _put_s3(self, url, filename, mtype, retry_count=3):
response = cStringIO.StringIO()
size = os.path.getsize(filename)
headers = ['Content-Type: ' + mtype]
@@ -168,10 +168,24 @@ class API_v3(API_v1):
c.setopt(pycurl.INFILESIZE, size)
c.setopt(pycurl.PUT, 1)
c.setopt(pycurl.WRITEFUNCTION, response.write)
- with open(filename, 'rb') as f:
- c.setopt(pycurl.INFILE, f)
- c.perform()
+ try:
+ with open(filename, 'rb') as f:
+ c.setopt(pycurl.INFILE, f)
+ c.perform()
+ except Exception as e:
+ if retry_count > 0:
+ # server could be reloading or something. give it a second and
+ # try again
+ print('Upload failed for %s, retrying in 2 seconds' % url)
+ time.sleep(2)
+ return self._put_s3(url, filename, mtype, retry_count - 1)
+ else:
+ return repr(e)
code = c.getinfo(pycurl.RESPONSE_CODE)
+ if code == 503 and retry_count > 0:
+ print('503 failure for %s, retrying in 2 seconds' % url)
+ time.sleep(2)
+ return self._put_s3(url, filename, mtype, retry_count - 1)
if code not in (200, 201):
return response.getvalue()