From d612e4938a09b94aee61353a52b4c5abee388f52 Mon Sep 17 00:00:00 2001 From: "hinoka@chromium.org" Date: Wed, 27 Aug 2014 14:00:41 +0000 Subject: [PATCH] Retry fetching patch from rietveld on a 404 Also added a tiny bit of exponential backoff. BUG=375479 Review URL: https://codereview.chromium.org/350433003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@291682 0039d316-1c4b-4281-b951-d872f2087c98 --- rietveld.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rietveld.py b/rietveld.py index f6ccaf928..0bf3d740e 100644 --- a/rietveld.py +++ b/rietveld.py @@ -97,7 +97,7 @@ class Rietveld(object): url = '/api/%d' % issue if messages: url += '?messages=true' - data = json.loads(self.get(url)) + data = json.loads(self.get(url, retry_on_404=True)) data['description'] = '\n'.join(data['description'].strip().splitlines()) return data @@ -389,7 +389,7 @@ class Rietveld(object): ctype, body = upload.EncodeMultipartFormData(data, []) return self._send(request_path, payload=body, content_type=ctype, **kwargs) - def _send(self, request_path, **kwargs): + def _send(self, request_path, retry_on_404=False, **kwargs): """Sends a POST/GET to Rietveld. Returns the response body.""" # rpc_server.Send() assumes timeout=None by default; make sure it's set # to something reasonable. @@ -420,7 +420,10 @@ class Rietveld(object): except urllib2.HTTPError, e: if retry >= (maxtries - 1): raise - if e.code not in (500, 502, 503): + flake_codes = [500, 502, 503] + if retry_on_404: + flake_codes.append(404) + if e.code not in flake_codes: raise except urllib2.URLError, e: if retry >= (maxtries - 1):