Skip to content

Commit

Permalink
compose - depends_on as object (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPreston authored May 31, 2024
1 parent 6ecb774 commit 84fa113
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
7 changes: 6 additions & 1 deletion ecs_composex/compose/compose_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def __init__(
self.cfn_environment = (
import_env_variables(self.environment) if self.environment else NoValue
)
self.depends_on = set_else_none("depends_on", self.definition, [], False)
self.depends_on: dict = set_else_none("depends_on", self.definition, {}, False)
if isinstance(self.depends_on, list):
services_names = [_s_name for _s_name in self.depends_on]
self.depends_on: dict = {}
for service_name in services_names:
self.depends_on[service_name] = {"condition": "service_started"}
self.docker_labels: dict = {}
self.import_docker_labels(self._definition)

Expand Down
14 changes: 10 additions & 4 deletions ecs_composex/ecs/ecs_family/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self, services: list[ComposeService], family_name):
self.managed_sidecars = []
self.name = family_name
self.family_hostname = self.name.replace("_", "-").lower()
self.services_depends_on = []
self.services_depends_on: dict = {}
self.template = set_template(self)
self.stack: ServiceStack = ServiceStack(
self.logical_name,
Expand Down Expand Up @@ -585,9 +585,15 @@ def set_services_to_services_dependencies(self):
"""
for service in self.services:
if service.depends_on:
for service_depends_on in service.depends_on:
if service_depends_on not in self.services_depends_on:
self.services_depends_on.append(service_depends_on)
if not isinstance(service.depends_on, dict):
raise TypeError(
"Service depends_on not a dict",
service.name,
service.depends_on,
)
for service_name, condition_def in service.depends_on.items():
if service_name not in self.services_depends_on:
self.services_depends_on[service_name] = {}

@property
def task_ephemeral_storage(self) -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ def __init__(
patch_fluent_service(
fluent_service, shared_volume, name, shared_volume.name, mount_path
)
fluent_service.depends_on.append(self.name)
fluent_service.depends_on[self.name] = {"condition": "service_started"}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def set_as_dependency_to_family_services(self, is_dependency: bool = True) -> No
if service is self:
continue
if self.name not in service.depends_on:
service.depends_on.append(self.name)
service.depends_on[self.name] = {"condition": "service_healthy"}
LOG.info(
f"{self.family.name}.{service.name} - Added {self.name} as startup dependency"
)
2 changes: 1 addition & 1 deletion ecs_composex/ecs/ecs_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def handle_families_dependencies(
"""
for family_def in families_post:
_family_title, _family_name = family_def
for family_name in settings.families[_family_title].services_depends_on:
for family_name in settings.families[_family_title].services_depends_on.keys():
for __family_title, __family_def in settings.families.items():
if __family_def.name == family_name:
family_title = __family_title
Expand Down
4 changes: 2 additions & 2 deletions ecs_composex/ecs/managed_sidecars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def set_as_dependency_to_family_services(self, is_dependency: bool = False) -> N
for service in self.family.ordered_services:
if is_dependency:
if self.name not in service.depends_on:
service.depends_on.append(self.name)
service.depends_on[self.name] = {"condition": "service_started"}
LOG.info(
f"{self.family.name}.{service.name} - Added {self.name} as startup dependency"
)
else:
if service.name not in self.depends_on:
self.depends_on.append(service.name)
self.depends_on[service.name] = {"condition": "service_started"}
LOG.info(
f"{self.family.name}.{self.name} - Added {service.name} as startup dependency"
)
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ x-dynamodb:
tableC:
Lookup:
Tags:
- name: tableC
- createdbycomposex: 'True'
name: tableC
createdbycomposex: 'True'
Services:
app03:
Access: RW
Expand All @@ -101,8 +101,8 @@ x-dynamodb:
tableD:
Lookup:
Tags:
- name: tableC
- createdbycomposex: 'False'
name: tableC
createdbycomposex: 'False'
Services:
app03:
Access: RW
Expand Down

0 comments on commit 84fa113

Please sign in to comment.