Skip to content

Commit

Permalink
ECS.ContainerDefinition.StopTimeout docker-compose.service.stop_grace…
Browse files Browse the repository at this point in the history
…_period (#718)

Co-authored-by: John Preston <1236150+JohnPreston@users.noreply.github.com>
  • Loading branch information
thorfi and JohnPreston authored Nov 29, 2023
1 parent 6c0299f commit f08fdaa
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ecs_composex/compose/compose_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,25 @@ def ulimits(self) -> Union[list, Ref]:

return rendered_limits if rendered_limits else NoValue

@property
def stop_grace_period(self):
"""
Method to import and determine StopTimeout
"""
__stop_grace_period = set_else_none("stop_grace_period", self.definition)
if not __stop_grace_period:
return NoValue
if not isinstance(__stop_grace_period, (str)):
raise TypeError(self.name)
stop_timeout = import_time_values_to_seconds(__stop_grace_period)
if stop_timeout < 2:
LOG.warning(f"services.{self.name} - stop_grace_period/StopTimeout {stop_timeout} < 2 - setting to 2")
stop_timeout = 2
elif stop_timeout > 120:
LOG.warning(f"services.{self.name} - stop_grace_period/StopTimeout {stop_timeout} > 120 - setting to 120")
stop_timeout = 120
return stop_timeout

@property
def x_iam(self) -> dict:
__iam = set_else_none(
Expand Down Expand Up @@ -941,6 +960,7 @@ def set_container_definition(self):
ReadonlyRootFilesystem=If(
USE_WINDOWS_OS_T, NoValue, keyisset("read_only", self.definition)
),
StopTimeout=self.stop_grace_period,
SystemControls=self.sysctls,
User=If(USE_WINDOWS_OS_T, NoValue, self.ecs_user)
if self.ecs_user != NoValue
Expand Down

0 comments on commit f08fdaa

Please sign in to comment.