updated container handling. hopefully removed potential error source.
This commit is contained in:
@ -188,7 +188,17 @@ class DockerClient
|
|||||||
{status: :ok, stderr: stderr.join, stdout: stdout.join}
|
{status: :ok, stderr: stderr.join, stdout: stdout.join}
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
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}
|
{status: :timeout}
|
||||||
ensure
|
ensure
|
||||||
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
|
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
|
||||||
|
@ -19,6 +19,20 @@ class DockerContainerPool
|
|||||||
@config ||= CodeOcean::Config.new(:docker).read(erb: true)[:pool]
|
@config ||= CodeOcean::Config.new(:docker).read(erb: true)[:pool]
|
||||||
end
|
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)
|
def self.create_container(execution_environment)
|
||||||
container = DockerClient.create_container(execution_environment)
|
container = DockerClient.create_container(execution_environment)
|
||||||
container.status = 'available'
|
container.status = 'available'
|
||||||
@ -37,14 +51,14 @@ class DockerContainerPool
|
|||||||
if(!container.nil?)
|
if(!container.nil?)
|
||||||
if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART)
|
if ((Time.now - container.start_time).to_i.abs > TIME_TILL_RESTART)
|
||||||
# remove container from @all_containers
|
# remove container from @all_containers
|
||||||
@all_containers[execution_environment.id]-=[container]
|
remove_from_all_containers(container, execution_environment)
|
||||||
|
|
||||||
# destroy container
|
# destroy container
|
||||||
DockerClient.destroy_container(container)
|
DockerClient.destroy_container(container)
|
||||||
|
|
||||||
# create new container and add it to @all_containers. will be added to @containers on return_container
|
# create new container and add it to @all_containers. will be added to @containers on return_container
|
||||||
container = create_container(@execution_environment)
|
container = create_container(execution_environment)
|
||||||
@all_containers[execution_environment.id]+=[container]
|
add_to_all_containers(container, execution_environment)
|
||||||
end
|
end
|
||||||
#container.status = 'used'
|
#container.status = 'used'
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user