Skip to content

using tenacity in download_binary function #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions report/firefox_code_coverage/codecoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import warnings

import requests
import tenacity

from firefox_code_coverage import taskcluster

Expand Down Expand Up @@ -67,29 +68,29 @@ def _save_tasks(response):
return tasks


def download_binary(url, path, retries=5):
@tenacity.retry(
stop=tenacity.stop_after_attempt(5),
wait=tenacity.wait_incrementing(start=7, increment=7),
reraise=True,
)
def download_binary(url, path):
"""Download a binary file from an url"""
for i in range(1, retries + 1):

try:
artifact = requests.get(url, stream=True)
artifact.raise_for_status()

with open(path, "wb") as f:
for chunk in artifact.iter_content(chunk_size=8192):
f.write(chunk)

except Exception:
try:
artifact = requests.get(url, stream=True)
artifact.raise_for_status()

with open(path, "wb") as f:
for chunk in artifact.iter_content(chunk_size=8192):
f.write(chunk)
break
except: # noqa: E722
try:
os.remove(path)
except OSError:
pass

if i == retries:
raise Exception(
"Download failed after {} retries - {}".format(retries, url)
)
os.remove(path)
except OSError:
pass

time.sleep(7 * i)
raise


def download_artifact(task_id, artifact, artifacts_path):
Expand Down
1 change: 1 addition & 0 deletions report/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
taskcluster==24.2.0
tenacity==6.0.0