diff --git a/lib/docker_container_pool.rb b/lib/docker_container_pool.rb index 47a8bf5c..7cc5fb51 100644 --- a/lib/docker_container_pool.rb +++ b/lib/docker_container_pool.rb @@ -20,7 +20,9 @@ class DockerContainerPool end def self.create_container(execution_environment) - DockerClient.create_container(execution_environment) + container = DockerClient.create_container(execution_environment) + container.status = 'available' + container end def self.return_container(container, execution_environment) @@ -32,18 +34,20 @@ class DockerContainerPool if config[:active] container = @containers[execution_environment.id].try(:shift) || nil - if((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART) - # remove container from @all_containers - @all_containers[execution_environment.id]-=[container] + if(!container.nil?) + if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART) + # remove container from @all_containers + @all_containers[execution_environment.id]-=[container] - # destroy container - DockerClient.destroy_container(container) + # destroy container + DockerClient.destroy_container(container) - # create new container and add it to @all_containers. will be added to @containers on return_container - container = create_container(@execution_environment) - @all_containers[execution_environment.id]+=[container] + # create new container and add it to @all_containers. will be added to @containers on return_container + container = create_container(@execution_environment) + @all_containers[execution_environment.id]+=[container] + end + #container.status = 'used' end - container.status = 'used' container else diff --git a/spec/lib/docker_container_pool_spec.rb b/spec/lib/docker_container_pool_spec.rb index f820a49b..464c3221 100644 --- a/spec/lib/docker_container_pool_spec.rb +++ b/spec/lib/docker_container_pool_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe DockerContainerPool do - let(:container) { double } + let(:container) { double(:start_time => Time.now, :status => 'available') } def reload_class load('docker_container_pool.rb')