Bug 1165347 - Use retries for symbol uploads. r=gps, a=NPOTB
authorTed Mielczarek <ted@mielczarek.org>
Fri, 15 May 2015 13:48:16 -0400
changeset 325139 94cc6dc1058daf85751bb50668720b25521b7611
parent 325138 47d264aec8899a13c7e4ef2313f17c2ebd1fb04e
child 325140 9792a6e67d71255ece30eb72c79accd0610705ec
push id9971
push userpaul@paul.cx
push dateMon, 25 Jan 2016 13:03:35 +0000
reviewersgps, NPOTB
bugs1165347
milestone38.0.1esrpre
Bug 1165347 - Use retries for symbol uploads. r=gps, a=NPOTB
toolkit/crashreporter/tools/upload_symbols.py
--- a/toolkit/crashreporter/tools/upload_symbols.py
+++ b/toolkit/crashreporter/tools/upload_symbols.py
@@ -10,16 +10,17 @@
 # Using this script requires you to have generated an authentication
 # token in the crash-stats web interface. You must put the token in a file
 # and set SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE to the path to the file in
 # the mozconfig you're using.
 
 from __future__ import print_function
 
 import os
+import redo
 import requests
 import sys
 
 from buildconfig import substs
 
 url = 'https://crash-stats.mozilla.com/symbols/upload'
 
 def main():
@@ -41,23 +42,25 @@ def main():
     if not os.path.isfile(token_file):
         print('Error: SOCORRO_SYMBOL_UPLOAD_TOKEN_FILE "{0}" does not exist!'.format(token_file), file=sys.stderr)
         return 1
     auth_token = open(token_file, 'r').read().strip()
 
     print('Uploading symbol file "{0}" to "{1}"...'.format(sys.argv[1], url))
 
     try:
-        r = requests.post(
-            url,
-            files={'symbols.zip': open(sys.argv[1], 'rb')},
-            headers={'Auth-Token': auth_token},
-            allow_redirects=False,
-            timeout=120,
-        )
+        with redo.retrying(requests.post,
+                           cleanup=lambda: print('Retrying...'),
+                           retry_exceptions=(requests.exceptions.RequestException,)) as post:
+            r = post(
+                url,
+                files={'symbols.zip': open(sys.argv[1], 'rb')},
+                headers={'Auth-Token': auth_token},
+                allow_redirects=False,
+                timeout=120)
     except requests.exceptions.RequestException as e:
         print('Error: {0}'.format(e))
         return 1
 
     if r.status_code >= 200 and r.status_code < 300:
         print('Uploaded successfully!')
     elif r.status_code < 400:
         print('Error: bad auth token? ({0})'.format(r.status_code),