Skip to content

Commit

Permalink
Add retries limit when pulling Terraform plan
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfontaine committed Apr 26, 2024
1 parent 20b9029 commit 9f5e95e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions spacemk/exporters/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ def _generate_migration_id(self, *args: str) -> str:
return slugify("_".join(args)).replace("-", "_")

def _get_plan(self, id_: str) -> dict:
pause_duration = 3 # seconds
max_retries = 40
retries = 0

while True:
data = self._extract_data_from_api(
path=f"/plans/{id_}", properties=["attributes.log-read-url", "attributes.status"]
Expand All @@ -957,8 +961,14 @@ def _get_plan(self, id_: str) -> dict:
data = {}
break
else:
logging.debug(f"Plan '{id_}' is not finished yet. Waiting 3 seconds before retrying.")
time.sleep(3)
logging.info(f"Plan '{id_}' is not finished yet. Waiting {pause_duration} seconds before retrying.")
time.sleep(pause_duration)

retries += 1
if retries >= max_retries:
logging.warning(f"Plan '{id_}' has not finished after {max_retries} retries. Giving up.")
data = {}
break

return data

Expand Down

0 comments on commit 9f5e95e

Please sign in to comment.