77
88logging .basicConfig (level = logging .INFO )
99
10+ RETRY_TIMES = 7
11+
1012
1113def 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 (7 )
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
3356def parse_arn (arn ):
0 commit comments