Skip to content

Fixing #392 and adhering to standards presented in #396 #400

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

Closed
wants to merge 2 commits into from
Closed
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
46 changes: 25 additions & 21 deletions report/firefox_code_coverage/codecoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests

from firefox_code_coverage import taskcluster
from tenacity import retry, stop_after_attempt, wait_exponential

FINISHED_STATUSES = ["completed", "failed", "exception"]
ALL_STATUSES = FINISHED_STATUSES + ["unscheduled", "pending", "running"]
Expand Down Expand Up @@ -67,30 +68,33 @@ def _save_tasks(response):
return tasks


def download_binary(url, path, retries=5):
"""Download a binary file from an url"""
for i in range(1, retries + 1):
@retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, max=64))
def retry_download_binary(url, path):
"""Download a binary file from an url with exponential backoff"""
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)
return
except: # noqa: E722
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:
raise Exception

time.sleep(7 * i)

def download_binary(url, path):
"""Wrapper function for retry_download_binary which raises exception after max number of retries"""
try:
retry_download_binary(url, path)
except:
raise Exception(
"Download failed after {} retries - {}".format(str(retry_download_binary.retry.statistics["attempt_number"])
, url)
)

def download_artifact(task_id, artifact, artifacts_path):
fname = os.path.join(
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