6161from ..ec2 import get_ec2_client
6262from ..instrumentation import get_instrumentation , has_instrumentation
6363from ..ssm import get_ssm_client
64- from .auto_scaling_mode_base import BaseAutoscaling
64+ from .auto_scaling_mode_base import AutoscalingProvider
6565
6666_logger = logging .getLogger (__name__ )
6767
6868
6969async def _analyze_current_cluster (
7070 app : FastAPI ,
71- auto_scaling_mode : BaseAutoscaling ,
71+ auto_scaling_mode : AutoscalingProvider ,
7272 allowed_instance_types : list [EC2InstanceType ],
7373) -> Cluster :
7474 app_settings = get_application_settings (app )
@@ -275,7 +275,7 @@ async def _make_pending_buffer_ec2s_join_cluster(
275275async def _try_attach_pending_ec2s (
276276 app : FastAPI ,
277277 cluster : Cluster ,
278- auto_scaling_mode : BaseAutoscaling ,
278+ auto_scaling_mode : AutoscalingProvider ,
279279 allowed_instance_types : list [EC2InstanceType ],
280280) -> Cluster :
281281 """label the drained instances that connected to the swarm which are missing the monitoring labels"""
@@ -340,10 +340,10 @@ async def _sorted_allowed_instance_types(app: FastAPI) -> list[EC2InstanceType]:
340340 allowed_instance_type_names
341341 ), "EC2_INSTANCES_ALLOWED_TYPES cannot be empty!"
342342
343- allowed_instance_types : list [
344- EC2InstanceType
345- ] = await ec2_client . get_ec2_instance_capabilities (
346- cast ( set [ InstanceTypeType ], set ( allowed_instance_type_names ) )
343+ allowed_instance_types : list [EC2InstanceType ] = (
344+ await ec2_client . get_ec2_instance_capabilities (
345+ cast ( set [ InstanceTypeType ], set ( allowed_instance_type_names ))
346+ )
347347 )
348348
349349 def _as_selection (instance_type : EC2InstanceType ) -> int :
@@ -421,7 +421,7 @@ async def _activate_drained_nodes(
421421
422422
423423async def _start_warm_buffer_instances (
424- app : FastAPI , cluster : Cluster , auto_scaling_mode : BaseAutoscaling
424+ app : FastAPI , cluster : Cluster , auto_scaling_mode : AutoscalingProvider
425425) -> Cluster :
426426 """starts warm buffer if there are assigned tasks, or if a hot buffer of the same type is needed"""
427427
@@ -544,7 +544,7 @@ async def _assign_tasks_to_current_cluster(
544544 app : FastAPI ,
545545 tasks : list ,
546546 cluster : Cluster ,
547- auto_scaling_mode : BaseAutoscaling ,
547+ auto_scaling_mode : AutoscalingProvider ,
548548) -> tuple [list , Cluster ]:
549549 """
550550 Evaluates whether a task can be executed on any instance within the cluster. If the task's resource requirements are met, the task is *denoted* as assigned to the cluster.
@@ -602,7 +602,7 @@ async def _find_needed_instances(
602602 unassigned_tasks : list ,
603603 available_ec2_types : list [EC2InstanceType ],
604604 cluster : Cluster ,
605- auto_scaling_mode : BaseAutoscaling ,
605+ auto_scaling_mode : AutoscalingProvider ,
606606) -> dict [EC2InstanceType , int ]:
607607 # 1. check first the pending task needs
608608 needed_new_instance_types_for_tasks : list [AssignedTasksToInstanceType ] = []
@@ -775,7 +775,7 @@ async def _launch_instances(
775775 app : FastAPI ,
776776 needed_instances : dict [EC2InstanceType , int ],
777777 tasks : list ,
778- auto_scaling_mode : BaseAutoscaling ,
778+ auto_scaling_mode : AutoscalingProvider ,
779779) -> list [EC2InstanceData ]:
780780 ec2_client = get_ec2_client (app )
781781 app_settings = get_application_settings (app )
@@ -1075,9 +1075,9 @@ async def _notify_based_on_machine_type(
10751075 launch_time_to_tasks : dict [datetime .datetime , list ] = collections .defaultdict (list )
10761076 now = datetime .datetime .now (datetime .UTC )
10771077 for instance in instances :
1078- launch_time_to_tasks [instance . ec2_instance . launch_time ] += (
1079- instance .assigned_tasks
1080- )
1078+ launch_time_to_tasks [
1079+ instance .ec2_instance . launch_time
1080+ ] += instance . assigned_tasks
10811081
10821082 for launch_time , tasks in launch_time_to_tasks .items ():
10831083 time_since_launch = now - launch_time
@@ -1147,7 +1147,7 @@ async def _drain_retired_nodes(
11471147async def _scale_down_unused_cluster_instances (
11481148 app : FastAPI ,
11491149 cluster : Cluster ,
1150- auto_scaling_mode : BaseAutoscaling ,
1150+ auto_scaling_mode : AutoscalingProvider ,
11511151) -> Cluster :
11521152 await auto_scaling_mode .try_retire_nodes (app )
11531153 cluster = await _deactivate_empty_nodes (app , cluster )
@@ -1157,7 +1157,7 @@ async def _scale_down_unused_cluster_instances(
11571157async def _scale_up_cluster (
11581158 app : FastAPI ,
11591159 cluster : Cluster ,
1160- auto_scaling_mode : BaseAutoscaling ,
1160+ auto_scaling_mode : AutoscalingProvider ,
11611161 allowed_instance_types : list [EC2InstanceType ],
11621162 unassigned_tasks : list ,
11631163) -> Cluster :
@@ -1209,7 +1209,7 @@ async def _scale_up_cluster(
12091209async def _autoscale_cluster (
12101210 app : FastAPI ,
12111211 cluster : Cluster ,
1212- auto_scaling_mode : BaseAutoscaling ,
1212+ auto_scaling_mode : AutoscalingProvider ,
12131213 allowed_instance_types : list [EC2InstanceType ],
12141214) -> Cluster :
12151215 # 1. check if we have pending tasks
@@ -1242,7 +1242,7 @@ async def _autoscale_cluster(
12421242
12431243
12441244async def _notify_autoscaling_status (
1245- app : FastAPI , cluster : Cluster , auto_scaling_mode : BaseAutoscaling
1245+ app : FastAPI , cluster : Cluster , auto_scaling_mode : AutoscalingProvider
12461246) -> None :
12471247 monitored_instances = list (
12481248 itertools .chain (
@@ -1271,7 +1271,7 @@ async def _notify_autoscaling_status(
12711271
12721272
12731273async def auto_scale_cluster (
1274- * , app : FastAPI , auto_scaling_mode : BaseAutoscaling
1274+ * , app : FastAPI , auto_scaling_mode : AutoscalingProvider
12751275) -> None :
12761276 """Check that there are no pending tasks requiring additional resources in the cluster (docker swarm)
12771277 If there are such tasks, this method will allocate new machines in AWS to cope with
0 commit comments