aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/utils.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-03-31 17:38:13 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-03-31 17:38:13 +0300
commitfe72c7e5c400a7e2cab87536cac8f26fb55f0cea (patch)
tree96543eaa3e21e34597a34ba4e7d661ef1daeb308 /project/utils.py
parentMakefile: more explicit requirements (diff)
downloadcmake-common-fe72c7e5c400a7e2cab87536cac8f26fb55f0cea.tar.gz
cmake-common-fe72c7e5c400a7e2cab87536cac8f26fb55f0cea.zip
project.boost: retry downloads
Diffstat (limited to '')
-rw-r--r--project/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/project/utils.py b/project/utils.py
index 5874eab..76557b1 100644
--- a/project/utils.py
+++ b/project/utils.py
@@ -4,10 +4,12 @@
# Distributed under the MIT License.
from contextlib import contextmanager
+import functools
import logging
import os.path
import subprocess
import tempfile
+import time
def normalize_path(s):
@@ -80,3 +82,23 @@ def env(name):
if name not in os.environ:
raise RuntimeError(f'undefined environment variable: {name}')
return os.environ[name]
+
+
+def retry(exc_type, timeout=5, retries=3, backoff=2):
+ def wrapper(func):
+ @functools.wraps(func)
+ def func2(*args, **kwargs):
+ current_timeout = timeout
+ for retry_n in range(retries):
+ try:
+ return func(*args, **kwargs)
+ except exc_type as e:
+ logging.exception(e)
+ if retry_n < retries:
+ logging.error('Retrying after %d seconds', current_timeout)
+ time.sleep(current_timeout)
+ current_timeout *= backoff
+ continue
+ raise
+ return func2
+ return wrapper