Retry log upload to swift

Retry 3 times to help with network failures.

Change-Id: Ia0a065c5b4343dd922b2af8cc29387384cdefe82
This commit is contained in:
Joshua Hesketh 2015-04-28 23:26:32 +10:00
parent 72992a7c3f
commit ff4ae27e5c
1 changed files with 13 additions and 2 deletions

View File

@ -363,7 +363,18 @@ class PostThread(threading.Thread):
files[key] = (fileinfo[key][0],
open(fileinfo[key][1], 'rb'),
fileinfo[key][2])
requests.post(url, headers=headers, data=payload, files=files)
for attempt in xrange(3):
try:
requests.post(url, headers=headers, data=payload, files=files)
break
except requests.exceptions.RequestException:
if attempt <= 3:
logging.exception(
"File posting error on attempt %d" % attempt)
continue
else:
raise
def run(self):
while True:
@ -372,7 +383,7 @@ class PostThread(threading.Thread):
self._post_file(*job)
except requests.exceptions.RequestException:
# Do our best to attempt to upload all the files
logging.exception("File posting error")
logging.exception("Error posting file after multiple attempts")
continue
except IOError:
# Do our best to attempt to upload all the files