Skip to content

Commit 3212b4a

Browse files
Use tenacity in download_binary (#401)
Fixes #392.
1 parent efb37af commit 3212b4a

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

report/firefox_code_coverage/codecoverage.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import warnings
1414

1515
import requests
16+
import tenacity
1617

1718
from firefox_code_coverage import taskcluster
1819

@@ -67,29 +68,29 @@ def _save_tasks(response):
6768
return tasks
6869

6970

70-
def download_binary(url, path, retries=5):
71+
@tenacity.retry(
72+
stop=tenacity.stop_after_attempt(5),
73+
wait=tenacity.wait_incrementing(start=7, increment=7),
74+
reraise=True,
75+
)
76+
def download_binary(url, path):
7177
"""Download a binary file from an url"""
72-
for i in range(1, retries + 1):
78+
79+
try:
80+
artifact = requests.get(url, stream=True)
81+
artifact.raise_for_status()
82+
83+
with open(path, "wb") as f:
84+
for chunk in artifact.iter_content(chunk_size=8192):
85+
f.write(chunk)
86+
87+
except Exception:
7388
try:
74-
artifact = requests.get(url, stream=True)
75-
artifact.raise_for_status()
76-
77-
with open(path, "wb") as f:
78-
for chunk in artifact.iter_content(chunk_size=8192):
79-
f.write(chunk)
80-
break
81-
except: # noqa: E722
82-
try:
83-
os.remove(path)
84-
except OSError:
85-
pass
86-
87-
if i == retries:
88-
raise Exception(
89-
"Download failed after {} retries - {}".format(retries, url)
90-
)
89+
os.remove(path)
90+
except OSError:
91+
pass
9192

92-
time.sleep(7 * i)
93+
raise
9394

9495

9596
def download_artifact(task_id, artifact, artifacts_path):

report/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
taskcluster==24.2.0
2+
tenacity==6.0.0

0 commit comments

Comments
 (0)