retry if file could not be uploaded
@@ -141,13 +141,25 @@ class Job(object):
f.write(chunk)
def post_file_to_api_server(self, url, path):
+ message = None
+ for _ in xrange(0, 5):
files = {'data': open(path, 'rb')}
+ try:
r = requests.post("%s%s" % (self.api_server, url),
headers=self.get_headers(),
files=files, timeout=600, verify=self.verify)
+ except Exception as e:
+ message = str(e)
+ time.sleep(5)
+ continue
if r.status_code != 200:
- raise Failure('Failed to upload file: %s' % r.text)
+ time.sleep(5)
+ message = r.text
+ else:
+ return
+
+ raise Failure('Failed to upload file: %s' % message)
def update_status(self, status, message=None):
if status == "running":
