11import logging
2+ from concurrent .futures import wait as futures_wait
23from datetime import datetime
34from typing import ClassVar , Dict , Optional , List , Type , Any , cast
45
56from attrs import define , field
7+
68from fix_plugin_aws .aws_client import AwsClient
79from fix_plugin_aws .resource .autoscaling import AwsAutoScalingGroup
8-
910from fix_plugin_aws .resource .base import AwsResource , GraphBuilder , AwsApiSpec
1011from fix_plugin_aws .resource .ec2 import AwsEc2Instance , AwsEc2SecurityGroup , AwsEc2Subnet
1112from fix_plugin_aws .resource .elb import AwsElb
1213from fix_plugin_aws .resource .elbv2 import AwsAlbTargetGroup
1314from fix_plugin_aws .resource .iam import AwsIamRole
1415from fix_plugin_aws .resource .kms import AwsKmsKey
1516from fix_plugin_aws .resource .s3 import AwsS3Bucket
17+ from fix_plugin_aws .utils import TagsValue , ToDict
1618from fixlib .baseresources import EdgeType , ModelReference
1719from fixlib .graph import Graph
1820from fixlib .json_bender import F , Bender , S , Bend , ForallBend
1921from fixlib .types import Json
2022from fixlib .utils import chunks
21- from fix_plugin_aws .utils import TagsValue , ToDict
2223
2324log = logging .getLogger ("fix.plugins.aws" )
2425service_name = "ecs"
@@ -1144,8 +1145,8 @@ def called_collect_apis(cls) -> List[AwsApiSpec]:
11441145 ]
11451146
11461147 @classmethod
1147- def collect (cls : Type [ AwsResource ] , json : List [Json ], builder : GraphBuilder ) -> None :
1148- def collect_task_definition (task_def_arn : str ) -> None :
1148+ def collect (cls , json : List [Json ], builder : GraphBuilder ) -> None :
1149+ def collect_task_definition (task_def_arn : str ) -> Optional [ AwsEcsTaskDefinition ] :
11491150 response = builder .client .get (
11501151 service_name ,
11511152 "describe-task-definition" ,
@@ -1159,16 +1160,20 @@ def collect_task_definition(task_def_arn: str) -> None:
11591160 task_definition ["tags" ] = tags
11601161 if task_definition_instance := cls .from_api (task_definition , builder ):
11611162 builder .add_node (task_definition_instance )
1163+ return task_definition_instance
1164+ return None
11621165
11631166 last_task_def_arn = ""
1167+ futures = []
11641168 for arn in cast (List [str ], json ):
11651169 # Skip task definition with same arn but older version
11661170 no_version = arn .rsplit (":" , 1 )[0 ]
11671171 if no_version == last_task_def_arn :
11681172 log .info (f"Skipping task definition { arn } as it is an older version of { last_task_def_arn } " )
11691173 continue
11701174 last_task_def_arn = no_version
1171- builder .submit_work (service_name , collect_task_definition , arn )
1175+ futures .append (builder .submit_work (service_name , collect_task_definition , arn ))
1176+ futures_wait (futures ) # only continue, when all task definitions are collected
11721177
11731178 def connect_in_graph (self , builder : GraphBuilder , source : Json ) -> None :
11741179 for role in [self .task_role_arn , self .execution_role_arn ]:
0 commit comments