Replacing a killed container only if required

This commit is contained in:
Sebastian Serth
2020-03-22 15:35:27 +01:00
parent 0338564bf2
commit 1cdc1b0647
2 changed files with 10 additions and 3 deletions

View File

@ -316,8 +316,15 @@ class DockerClient
DockerContainerPool.remove_from_all_containers(container, @execution_environment, bypass_semaphore: true)
# create new container and add it to @all_containers and @containers.
# ToDo: How long does creating a new cotainer take? We're still locking the semaphore.
new_container = self.class.create_container(@execution_environment)
DockerContainerPool.add_to_all_containers(new_container, @execution_environment, bypass_semaphore: true)
missing_counter_count = execution_environment.pool_size - @all_containers[execution_environment.id].length
if missing_counter_count > 0
Rails.logger.error('kill_container: Creating a new container.')
new_container = self.class.create_container(@execution_environment)
DockerContainerPool.add_to_all_containers(new_container, @execution_environment, bypass_semaphore: true)
else
Rails.logger.error('Container killed and removed for ' + execution_environment.to_s + ' but not creating a new one. Currently, ' + missing_counter_count.abs + ' more containers than the configured pool size are available.')
end
DockerContainerPool.release_semaphore
end

View File

@ -134,7 +134,7 @@ class DockerContainerPool
remove_from_all_containers(container, execution_environment, bypass_semaphore: true)
missing_counter_count = execution_environment.pool_size - @all_containers[execution_environment.id].length
if missing_counter_count > 0
Rails.logger.error('Creating a new container and returning that.')
Rails.logger.error('replace_broken_container: Creating a new container and returning that.')
new_container = create_container(execution_environment)
DockerContainerPool.add_to_all_containers(new_container, execution_environment, bypass_semaphore: true)
else