Skip to content

Commit fabb809

Browse files
committed
stupid simple retry logic for download
1 parent 3f0897a commit fabb809

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

bazelisk.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767

6868
BAZEL_UPSTREAM = "bazelbuild"
6969

70+
BAZEL_DOWNLOAD_RETRIES = 5
71+
BAZEL_DOWNLOAD_RETRY_WAIT_SECS = 5
72+
7073

7174
def decide_which_bazel_version_to_use():
7275
# Check in this order:
@@ -180,8 +183,7 @@ def get_version_history(bazelisk_directory):
180183
),
181184
# This only handles versions with numeric components, but that is fine
182185
# since prerelease versions have been excluded.
183-
key=lambda version: tuple(int(component)
184-
for component in version.split('.')),
186+
key=lambda version: tuple(int(component) for component in version.split(".")),
185187
reverse=True,
186188
)
187189

@@ -352,8 +354,16 @@ def download(url, destination_path):
352354
if creds is not None:
353355
auth = base64.b64encode(("%s:%s" % (creds[0], creds[2])).encode("ascii"))
354356
request.add_header("Authorization", "Basic %s" % auth.decode("utf-8"))
355-
with closing(urlopen(request)) as response, open(destination_path, "wb") as file:
356-
shutil.copyfileobj(response, file)
357+
358+
tries = BAZEL_DOWNLOAD_RETRIES
359+
while tries > 0:
360+
try:
361+
with closing(urlopen(request)) as response, open(destination_path, "wb") as file:
362+
shutil.copyfileobj(response, file)
363+
break
364+
except Exception:
365+
tries -= 1
366+
time.sleep(secs=BAZEL_DOWNLOAD_RETRY_WAIT_SECS)
357367

358368

359369
def get_bazelisk_directory():

0 commit comments

Comments
 (0)