Skip to content

Commit 7661764

Browse files
committed
Retry destroying aws infrastructure
1 parent f6d8220 commit 7661764

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

scripts/aws-force-destroy.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,34 @@
77

88
logging.basicConfig(level=logging.INFO)
99

10+
RETRY_TIMES = 5
11+
1012

1113
def main():
1214
parser = argparse.ArgumentParser(description="Force Destroy AWS environment.")
1315
parser.add_argument("-c", "--config", help="nebari configuration", required=True)
1416
args = parser.parse_args()
1517

16-
handle_force_destroy(args)
18+
success = False
19+
retries = 0
20+
21+
# sometimes just need to retry
22+
while retries < RETRY_TIMES and not success:
23+
success = handle_force_destroy(args)
24+
if not success:
25+
logging.info(f"Attempt {retries+1} failed!")
26+
time.sleep(5)
27+
retries += 1
28+
29+
30+
def handle_force_destroy(args) -> bool:
31+
"""Force Destroy AWS environment.
1732
33+
If the environment is successfully destroyed, return True.
34+
If the environment is not successfully destroyed, return False.
1835
19-
def handle_force_destroy(args):
36+
:rtype: bool
37+
"""
2038
config_filename = Path(args.config)
2139
if not config_filename.is_file():
2240
raise ValueError(
@@ -25,9 +43,14 @@ def handle_force_destroy(args):
2543

2644
config = load_yaml(config_filename)
2745

28-
# Don't verify(config) in case the schema has changed - just pick out the important bits and tear down
46+
# Try to destroy the AWS environment
47+
try:
48+
force_destroy_configuration(config)
49+
except Exception as e:
50+
logging.error(f"Failed to destroy AWS environment: {e}")
51+
return False
2952

30-
force_destroy_configuration(config)
53+
return True
3154

3255

3356
def parse_arn(arn):

0 commit comments

Comments
 (0)