From e618f7c9e695a597286795c26d5c65fd3d9f84cd Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Wed, 3 Jul 2024 15:30:09 -0300 Subject: [PATCH] Do some pruning when scaling --- src/funko.cr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/funko.cr b/src/funko.cr index 09ff7b3..e5e8ee1 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -99,7 +99,6 @@ module Funko Log.info { "Adding instance" } (current_scale...new_scale).each { id = create_container - sleep 0.2.seconds start(id) } else @@ -112,6 +111,12 @@ module Funko break if current_scale == new_scale } end + + # And now, let's kill all the containers that are NOT running + containers.select { |container| container.@state != "running" }.each { |container| + Log.info { "Pruning dead instance" } + docker_api.containers.delete(container.@id) + } end # Setup the target directory `path` with all the files needed