diff options
author | Ben Copeland <ben.copeland@linaro.org> | 2017-12-20 13:38:45 +0000 |
---|---|---|
committer | Ben Copeland <ben.copeland@linaro.org> | 2017-12-20 13:38:45 +0000 |
commit | 3eab747ff8ea7a46f8e292ad6f439b9f609dd28a (patch) | |
tree | 33c36d575e6f59744879b007dadd49906d035917 | |
parent | 9809f07283e0271290f61dacc825294ee86266a3 (diff) |
Improve retry logic
Instead of retrying every 2 seconds, lets retry 2 seconds and double it.
If we repeat this 5 times, a total of 36 seconds is added on the retry
attempts.
Change-Id: I96c2ed2dc125a74411553a2a72bb7bbfc57116fb
-rwxr-xr-x | linaro-cp.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/linaro-cp.py b/linaro-cp.py index 1a1921a..24d8636 100755 --- a/linaro-cp.py +++ b/linaro-cp.py @@ -23,8 +23,8 @@ class API_v1(object): self.build_info = build_info self.api_key = api_key - def _upload_data(self, url, data=None, files=None, headers=None, retry_count=3): - while retry_count: + def _upload_data(self, url, data=None, files=None, headers=None, retry_count=5): + for x in range(retry_count): try: resp = requests.post(url, headers=headers, data=data, files=files, timeout=61) if resp.status_code in (200, 201): @@ -33,8 +33,8 @@ class API_v1(object): print("Unsuccessful status:", resp.status_code) except Exception as e: print(e) - print('Upload failed for %s, retrying in 2 seconds' % url) - time.sleep(2) + print('Upload failed for %s, retry attempt %s' % url, x) + time.sleep(2 * x + 1) retry_count -= 1 raise Exception("LLP request failed") @@ -135,10 +135,10 @@ class API_v3(API_v1): super(API_v3, self).__init__(server, build_info, api_key) self.api_base = server + '/api/v3/publish/' - def _put_s3(self, url, filename, mtype, retry_count=3): + def _put_s3(self, url, filename, mtype, retry_count=5): size = os.path.getsize(filename) headers = {'Content-Type': mtype, 'Content-Length': str(size)} - while retry_count: + for x in range(retry_count): try: with open(filename, 'rb') as f: resp = requests.put(url, headers=headers, data=f, timeout=61) @@ -149,7 +149,7 @@ class API_v3(API_v1): except Exception as e: print(e) print('Upload failed for %s, retrying in 2 seconds' % url) - time.sleep(2) + time.sleep(2 * x + 1) retry_count -= 1 raise Exception("S3 upload failed") |