Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
feat: add retry when fetching current image
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Graber committed Dec 11, 2023
1 parent 512d9ff commit 49e57dc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tubular/scripts/retrieve_latest_base_ami.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def retrieve_latest_base_ami(environment, deployment, play, override, ubuntu_ver
if url == "":
url = "https://cloud-images.ubuntu.com/query/focal/server/released.current.txt"
click.secho('Using default focal images.\n: {}'.format(url), fg='red')
data = requests.get(url)
data = get_with_retry(url)
parse_ami = re.findall('ebs-ssd(.+?)amd64(.+?){}(.+?)hvm'.format(region), data.content.decode('utf-8'))
ami_id = parse_ami[0][2].strip()
click.secho('AMI ID fetched from Ubuntu Cloud : {}'.format(ami_id), fg='red')
Expand Down Expand Up @@ -110,6 +110,14 @@ def retrieve_latest_base_ami(environment, deployment, play, override, ubuntu_ver

sys.exit(0)

@backoff.on_exception(
backoff.expo,
requests.exceptions.RequestException,
max_tries=5, jitter=backoff.random_jitter, on_backoff=_backoff_logger,
)
def get_with_retry(url):
data = requests.get(url)
return data

if __name__ == "__main__":
retrieve_latest_base_ami() # pylint: disable=no-value-for-parameter

0 comments on commit 49e57dc

Please sign in to comment.