Skip to content

bot: replaced retry function with Tenacity #366

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 25 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3b22de0
Updated taskcluster.py to use Tenacity for retrying perform_download.…
seb-sojka Jan 6, 2020
ff03947
Uploader.py in bot uses tenacity to retrying gcp_ingest in gcp functi…
seb-sojka Jan 6, 2020
5da78f3
Merge branch 'master' into removeRetryFunction
seb-sojka Jan 7, 2020
45cd5bb
Remove extra : from retry in taskcluster.py
seb-sojka Jan 7, 2020
77b8b91
Add tenacity to requirementspdev.txt to intall
seb-sojka Jan 7, 2020
de3b91b
Add tenacity to requirements.txt for install and removed it from requ…
seb-sojka Jan 7, 2020
55113e8
Updated taskcluster.py and uploader.py to run tenacity
seb-sojka Jan 9, 2020
5e4b422
Add call for perform_download function
seb-sojka Jan 9, 2020
a825a35
Corrected error with import tenacity instead of from
seb-sojka Jan 9, 2020
ce6d80c
Merge branch 'master' into removeRetryFunction
seb-sojka Jan 10, 2020
f6883ba
Updated uploader.py to use tenacity functions
seb-sojka Jan 11, 2020
77a4eb0
Tabs to spaces and added tenacity to know third party
seb-sojka Jan 11, 2020
2e64b0d
Update requirements.txt and requirements-dev.txt with sorting. Update…
seb-sojka Jan 11, 2020
2a6ea47
Added back class RunException to utils.py and removed import time
seb-sojka Jan 11, 2020
e895b12
Moved perform download function outside of download artifact
seb-sojka Jan 11, 2020
1fbd552
Added agruements from urls and artifact path for perform download
seb-sojka Jan 11, 2020
da866ce
Moved perform download back into download_artifact function
seb-sojka Jan 11, 2020
ec20dea
Removed extra perform_download function and set reraise to try for re…
seb-sojka Jan 11, 2020
efbe2e9
Remove the function RaiseExpection and used expection instead in util…
seb-sojka Jan 14, 2020
3739f47
Merge branch 'master' into removeRetryFunction
seb-sojka Jan 15, 2020
744e114
Added back # noqa for lines too long in test_taskcluster.py
seb-sojka Jan 15, 2020
6e697bb
Merge branch 'removeRetryFunction' of github.com:seb-sojka/code-cover…
seb-sojka Jan 15, 2020
fe38b22
Merge branch 'master' into removeRetryFunction
seb-sojka Jan 28, 2020
bdb6464
Pre-commit changed retry style
seb-sojka Jan 28, 2020
acc1076
Merge branch 'master' into removeRetryFunction
seb-sojka Jan 28, 2020
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
6 changes: 3 additions & 3 deletions bot/code_coverage_bot/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import taskcluster
from taskcluster.helper import TaskclusterConfig

from code_coverage_bot.utils import retry
import tenacity

logger = structlog.getLogger(__name__)
taskcluster_config = TaskclusterConfig("https://firefox-ci-tc.services.mozilla.com")
Expand Down Expand Up @@ -87,6 +87,7 @@ def download_artifact(artifact_path, task_id, artifact_name):
url = queue.buildUrl("getLatestArtifact", task_id, artifact_name)
logger.debug("Downloading artifact", url=url)

@tenacity.retry(wait=tenacity.wait_fixed(30), stop=tenacity.stop_after_attempt(5))
def perform_download():
r = requests.get(url, stream=True)
r.raise_for_status()
Expand All @@ -97,8 +98,7 @@ def perform_download():

if artifact_path.endswith(".zip") and not is_zipfile(artifact_path):
raise BadZipFile("File is not a zip file")

retry(perform_download)
perform_download()


def is_coverage_task(task):
Expand Down
11 changes: 6 additions & 5 deletions bot/code_coverage_bot/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import zstandard as zstd

from code_coverage_bot.secrets import secrets
from code_coverage_bot.utils import retry
from code_coverage_tools.gcp import get_bucket

import tenacity

logger = structlog.get_logger(__name__)
GCP_COVDIR_PATH = "{repository}/{revision}/{platform}:{suite}.json.zstd"

Expand Down Expand Up @@ -45,10 +46,10 @@ def gcp(repository, revision, report, platform, suite):
logger.info("Uploaded {} on {}".format(path, bucket))

# Trigger ingestion on backend
retry(
lambda: gcp_ingest(repository, revision, platform, suite),
retries=10,
wait_between_retries=60,
@tenacity.retry(
retry = retry_if_exception(lambda: gcp_ingest(repository, revision, platform, suite)),
stop=stop_after_attempt(10),
wait=wait_fixed(60)
)

return blob
Expand Down
22 changes: 0 additions & 22 deletions bot/code_coverage_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@

log = structlog.get_logger(__name__)


class RunException(Exception):
"""
Exception used to stop retrying
"""


def retry(
operation, retries=5, wait_between_retries=30, exception_to_break=RunException
):
while True:
try:
return operation()
except Exception as e:
if isinstance(e, exception_to_break):
raise
retries -= 1
if retries == 0:
raise
time.sleep(wait_between_retries)


def hide_secrets(text, secrets):
if type(text) is bytes:
encode_secret, xxx = lambda x: bytes(x, encoding="utf-8"), b"XXX"
Expand Down
2 changes: 1 addition & 1 deletion bot/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ jsonschema==3.2.0
pre-commit==1.21.0
pytest==5.3.2
pytest-responses==0.4.0
responses==0.10.9
responses==0.10.9
1 change: 1 addition & 0 deletions bot/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ libmozdata==0.1.64
pytoml==0.1.21
pytz==2019.3
zstandard==0.13.0
tenacity==6.0.0