Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1099)

Unified Diff: infra_libs/httplib2_utils.py

Issue 2153483002: RetriableHttp to sleep between retries (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | infra_libs/test/httplib2_utils_test.py » ('j') | infra_libs/test/httplib2_utils_test.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: infra_libs/httplib2_utils.py
diff --git a/infra_libs/httplib2_utils.py b/infra_libs/httplib2_utils.py
index 1a48a90805af775c5bd5d01d0b235cfcc3049ab3..a37447f0259cc844527117439ca6ee24141e2be5 100644
--- a/infra_libs/httplib2_utils.py
+++ b/infra_libs/httplib2_utils.py
@@ -165,16 +165,19 @@ def get_authenticated_http(credentials_filename,
class RetriableHttp(object):
"""A httplib2.Http object that retries on failure."""
- def __init__(self, http, max_tries=5, retrying_statuses_fn=None):
+ def __init__(self, http, max_tries=5, backoff_time=1,
+ retrying_statuses_fn=None):
"""
Args:
http: an httplib2.Http instance
max_tries: a number of maximum tries
+ backoff_time: a number of seconds to sleep between retries
retrying_statuses_fn: a function that returns True if a given status
should be retried
"""
self._http = http
self._max_tries = max_tries
+ self._backoff_time = backoff_time
self._retrying_statuses_fn = retrying_statuses_fn or \
set(range(500,599)).__contains__
@@ -199,6 +202,7 @@ class RetriableHttp(object):
'will retry')
if i == self._max_tries:
raise
+ time.sleep(self._backoff_time)
return response, content
@@ -206,7 +210,8 @@ class RetriableHttp(object):
return getattr(self._http, name)
def __setattr__(self, name, value):
- if name in ('request', '_http', '_max_tries', '_retrying_statuses_fn'):
+ if name in ('request', '_http', '_max_tries', '_backoff_time',
+ '_retrying_statuses_fn'):
self.__dict__[name] = value
else:
setattr(self._http, name, value)
« no previous file with comments | « no previous file | infra_libs/test/httplib2_utils_test.py » ('j') | infra_libs/test/httplib2_utils_test.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698