updated container handling. hopefully removed potential error source.

This commit is contained in:
Ralf Teusner
2015-04-22 15:00:01 +02:00
parent a7087824b1
commit e515afe619
2 changed files with 28 additions and 4 deletions

View File

@ -188,7 +188,17 @@ class DockerClient
{status: :ok, stderr: stderr.join, stdout: stdout.join}
end
rescue Timeout::Error
container.restart if RECYCLE_CONTAINERS
#container.restart if RECYCLE_CONTAINERS
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
# destroy container
destroy_container(container)
if(RECYCLE_CONTAINERS)
# create new container and add it to @all_containers. will be added to @containers on return_container
container = create_container(execution_environment)
DockerContainerPool.add_to_all_containers(container, execution_environment)
end
{status: :timeout}
ensure
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)

View File

@ -19,6 +19,20 @@ class DockerContainerPool
@config ||= CodeOcean::Config.new(:docker).read(erb: true)[:pool]
end
def self.remove_from_all_containers(container, execution_environment)
@all_containers[execution_environment.id]-=[container]
if(@containers[execution_environment.id].include?(container))
@containers[execution_environment.id]-=[container]
end
end
def self.add_to_all_containers(container, execution_environment)
@all_containers[execution_environment.id]+=[container]
if(!@containers[execution_environment.id].include?(container))
@containers[execution_environment.id]+=[container]
end
end
def self.create_container(execution_environment)
container = DockerClient.create_container(execution_environment)
container.status = 'available'
@ -37,14 +51,14 @@ class DockerContainerPool
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]
remove_from_all_containers(container, execution_environment)
# 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]
container = create_container(execution_environment)
add_to_all_containers(container, execution_environment)
end
#container.status = 'used'
end