Files
mongo/buildscripts/bazel_rules_mongo/utils/downloads.bzl
Trevor Guidry 831fd48363 SERVER-102675 Bundle up codeowners tooling into bazel rule (#33854)
GitOrigin-RevId: f164862110f362cb2daee5cb41e39ce184ea5d27
2025-04-10 02:43:49 +00:00

24 lines
969 B
Python

def retry_download(ctx, tries, **kwargs):
sleep_time = 1
for attempt in range(tries):
is_retriable = attempt + 1 < tries
result = ctx.download(allow_fail = is_retriable, **kwargs)
if result.success:
return result
else:
print("Download failed (Attempt #%s), sleeping for %s seconds then retrying..." % (attempt + 1, sleep_time))
ctx.execute(["sleep", str(sleep_time)])
sleep_time *= 2
def retry_download_and_extract(ctx, tries, **kwargs):
sleep_time = 1
for attempt in range(tries):
is_retriable = attempt + 1 < tries
result = ctx.download_and_extract(allow_fail = is_retriable, **kwargs)
if result.success:
return result
else:
print("Download failed (Attempt #%s), sleeping for %s seconds then retrying..." % (attempt + 1, sleep_time))
ctx.execute(["sleep", str(sleep_time)])
sleep_time *= 2