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

Unified Diff: tools/telemetry/third_party/gsutilz/third_party/retry-decorator/retry_decorator/retry_decorator.py

Issue 1264873003: Add gsutil/third_party to telemetry/third_party/gsutilz/third_party. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove httplib2 Created 5 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
Index: tools/telemetry/third_party/gsutilz/third_party/retry-decorator/retry_decorator/retry_decorator.py
diff --git a/tools/telemetry/third_party/gsutilz/third_party/retry-decorator/retry_decorator/retry_decorator.py b/tools/telemetry/third_party/gsutilz/third_party/retry-decorator/retry_decorator/retry_decorator.py
new file mode 100755
index 0000000000000000000000000000000000000000..466396a3b9199c1b49089bf833f0088dfbabbf3b
--- /dev/null
+++ b/tools/telemetry/third_party/gsutilz/third_party/retry-decorator/retry_decorator/retry_decorator.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+from __future__ import print_function
+
+import traceback
+import logging
+import time
+import random
+import sys
+
+def retry(ExceptionToCheck, tries=10, timeout_secs=1.0, logger=None):
+ """
+ Retry calling the decorated function using an exponential backoff.
+ """
+ def deco_retry(f):
+ def f_retry(*args, **kwargs):
+ mtries, mdelay = tries, timeout_secs
+ while mtries > 1:
+ try:
+ return f(*args, **kwargs)
+ except ExceptionToCheck as e:
+ #traceback.print_exc()
+ half_interval = mdelay * 0.10 #interval size
+ actual_delay = random.uniform(mdelay - half_interval, mdelay + half_interval)
+ msg = "Retrying in %.2f seconds ..." % actual_delay
+ if logger is None:
+ logging.exception(msg)
+ else:
+ logger.exception(msg)
+ time.sleep(actual_delay)
+ mtries -= 1
+ mdelay *= 2
+ return f(*args, **kwargs)
+ return f_retry # true decorator
+ return deco_retry
+
+

Powered by Google App Engine
This is Rietveld 408576698