Skip to content

Commit

Permalink
Fix pull_licenses_java script retry broken for tenacity 8.5 (#32626)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abacn authored Oct 2, 2024
1 parent 8bdea3d commit e91882f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sdks/java/container/license_scripts/pull_licenses_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
RETRY_NUM = 9
THREADS = 16

# workaround of a breaking change introduced in tenacity 8.5+
# See https://github.com/jd/tenacity/issues/486
def resolve_retry_number(retried_fn):
return retried_fn.retry.statistics.get("attempt_number") or \
retried_fn.statistics.get("attempt_number")

@retry(reraise=True,
wait=wait_fixed(5),
stop=stop_after_attempt(RETRY_NUM))
Expand Down Expand Up @@ -72,7 +78,7 @@ def pull_from_url(file_name, url, dep, no_list):
url=url, file_name=file_name, dep=dep))
except URLError as e:
traceback.print_exc()
if pull_from_url.retry.statistics["attempt_number"] < RETRY_NUM:
if resolve_retry_number(pull_from_url) < RETRY_NUM:
logging.error('Invalid url for {dep}: {url}. Retrying...'.format(
url=url, dep=dep))
raise
Expand All @@ -85,7 +91,7 @@ def pull_from_url(file_name, url, dep, no_list):
return
except HTTPError as e:
traceback.print_exc()
if pull_from_url.retry.statistics["attempt_number"] < RETRY_NUM:
if resolve_retry_number(pull_from_url) < RETRY_NUM:
logging.info(
'Received {code} from {url} for {dep}. Retrying...'.format(
code=e.code, url=url, dep=dep))
Expand All @@ -99,7 +105,7 @@ def pull_from_url(file_name, url, dep, no_list):
return
except Exception as e:
traceback.print_exc()
if pull_from_url.retry.statistics["attempt_number"] < RETRY_NUM:
if resolve_retry_number(pull_from_url) < RETRY_NUM:
logging.error(
'Error occurred when pull {file_name} from {url} for {dep}. Retrying...'
.format(url=url, file_name=file_name, dep=dep))
Expand Down

0 comments on commit e91882f

Please sign in to comment.