Skip to content

Commit

Permalink
waiting for instances in running state before resuming autoscaling group
Browse files Browse the repository at this point in the history
  • Loading branch information
diodonfrost committed Feb 24, 2020
1 parent e2c785c commit 53f14f7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package/scheduler/autoscaling_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def start(self, tag_key: str, tag_value: str) -> None:
"""
asg_list = self.list_groups(tag_key, tag_value)
instance_list = self.list_instances(asg_list)
instance_running_ids = []

# Start autoscaling instance
for ec2_instance in instance_list:
Expand All @@ -73,6 +74,17 @@ def start(self, tag_key: str, tag_value: str) -> None:
print("Start autoscaling instances {0}".format(ec2_instance))
except ClientError as exc:
ec2_exception("instance", ec2_instance, exc)
else:
instance_running_ids.append(ec2_instance)

try:
instance_waiter = self.ec2.get_waiter("instance_running")
instance_waiter.wait(
InstanceIds=instance_running_ids,
WaiterConfig={"Delay": 15, "MaxAttempts": 15},
)
except ClientError as exc:
ec2_exception("waiter", instance_waiter, exc)

for asg_name in asg_list:
try:
Expand Down

0 comments on commit 53f14f7

Please sign in to comment.