Make maxtries for Rietveld configurable

R=machenbach
TBR=maruel

BUG=459855

Review URL: https://codereview.chromium.org/932333003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294121 0039d316-1c4b-4281-b951-d872f2087c98
parent 48603a4d
...@@ -37,7 +37,7 @@ upload.LOGGER.setLevel(logging.WARNING) # pylint: disable=E1103 ...@@ -37,7 +37,7 @@ upload.LOGGER.setLevel(logging.WARNING) # pylint: disable=E1103
class Rietveld(object): class Rietveld(object):
"""Accesses rietveld.""" """Accesses rietveld."""
def __init__(self, url, email, password, extra_headers=None): def __init__(self, url, email, password, extra_headers=None, maxtries=None):
self.url = url.rstrip('/') self.url = url.rstrip('/')
# Email and password are accessed by commit queue, keep them. # Email and password are accessed by commit queue, keep them.
self.email = email self.email = email
...@@ -64,6 +64,8 @@ class Rietveld(object): ...@@ -64,6 +64,8 @@ class Rietveld(object):
self._xsrf_token = None self._xsrf_token = None
self._xsrf_token_time = None self._xsrf_token_time = None
self._maxtries = maxtries or 40
def xsrf_token(self): def xsrf_token(self):
if (not self._xsrf_token_time or if (not self._xsrf_token_time or
(time.time() - self._xsrf_token_time) > 30*60): (time.time() - self._xsrf_token_time) > 30*60):
...@@ -413,8 +415,7 @@ class Rietveld(object): ...@@ -413,8 +415,7 @@ class Rietveld(object):
old_error_exit(msg) old_error_exit(msg)
upload.ErrorExit = trap_http_500 upload.ErrorExit = trap_http_500
maxtries = 40 for retry in xrange(self._maxtries):
for retry in xrange(maxtries):
try: try:
logging.debug('%s' % request_path) logging.debug('%s' % request_path)
result = self.rpc_server.Send(request_path, **kwargs) result = self.rpc_server.Send(request_path, **kwargs)
...@@ -422,7 +423,7 @@ class Rietveld(object): ...@@ -422,7 +423,7 @@ class Rietveld(object):
# How nice. # How nice.
return result return result
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
if retry >= (maxtries - 1): if retry >= (self._maxtries - 1):
raise raise
flake_codes = [500, 502, 503] flake_codes = [500, 502, 503]
if retry_on_404: if retry_on_404:
...@@ -430,14 +431,14 @@ class Rietveld(object): ...@@ -430,14 +431,14 @@ class Rietveld(object):
if e.code not in flake_codes: if e.code not in flake_codes:
raise raise
except urllib2.URLError, e: except urllib2.URLError, e:
if retry >= (maxtries - 1): if retry >= (self._maxtries - 1):
raise raise
if (not 'Name or service not known' in e.reason and if (not 'Name or service not known' in e.reason and
not 'EOF occurred in violation of protocol' in e.reason): not 'EOF occurred in violation of protocol' in e.reason):
# Usually internal GAE flakiness. # Usually internal GAE flakiness.
raise raise
except ssl.SSLError, e: except ssl.SSLError, e:
if retry >= (maxtries - 1): if retry >= (self._maxtries - 1):
raise raise
if not 'timed out' in str(e): if not 'timed out' in str(e):
raise raise
...@@ -575,7 +576,8 @@ class JwtOAuth2Rietveld(Rietveld): ...@@ -575,7 +576,8 @@ class JwtOAuth2Rietveld(Rietveld):
client_email, client_email,
client_private_key_file, client_private_key_file,
private_key_password=None, private_key_password=None,
extra_headers=None): extra_headers=None,
maxtries=None):
# These attributes are accessed by commit queue. Keep them. # These attributes are accessed by commit queue. Keep them.
self.email = client_email self.email = client_email
...@@ -598,6 +600,8 @@ class JwtOAuth2Rietveld(Rietveld): ...@@ -598,6 +600,8 @@ class JwtOAuth2Rietveld(Rietveld):
self._xsrf_token = None self._xsrf_token = None
self._xsrf_token_time = None self._xsrf_token_time = None
self._maxtries = 40 or maxtries
class CachingRietveld(Rietveld): class CachingRietveld(Rietveld):
"""Caches the common queries. """Caches the common queries.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment