fix&refactor: improve connection retry logic and remove unnecessary wait time for AWS instance readiness

This commit is contained in:
adlsdztony
2025-05-28 13:05:32 +08:00
parent f3d3cd9ed0
commit d8ae209162
2 changed files with 12 additions and 3 deletions

View File

@@ -51,7 +51,17 @@ class SetupController:
"parameters": dick like {str, Any} providing the keyword
parameters
}
"""
"""
# make sure connection can be established
retry = 0
while retry < 30:
try:
_ = requests.get(self.http_server + "/terminal")
break
except:
time.sleep(5)
retry += 1
logger.info(f"try to connect {self.http_server}, retry {retry}/30")
for cfg in config:
config_type: str = cfg["type"]

View File

@@ -145,8 +145,7 @@ class AWSProvider(Provider):
logger.info(f"New instance {new_instance_id} launched from snapshot {snapshot_name}.")
logger.info(f"Waiting for instance {new_instance_id} to be running...")
ec2_client.get_waiter('instance_running').wait(InstanceIds=[new_instance_id])
# wait 60 seconds for the instance to be ready
time.sleep(60)
logger.info(f"Instance {new_instance_id} is ready.")
return new_instance_id