restart containers if they are running for more than 15 minutes (900 seconds)
This commit is contained in:
@ -53,6 +53,7 @@ class DockerClient
|
|||||||
local_workspace_path = generate_local_workspace_path
|
local_workspace_path = generate_local_workspace_path
|
||||||
FileUtils.mkdir(local_workspace_path)
|
FileUtils.mkdir(local_workspace_path)
|
||||||
container.start(container_start_options(execution_environment, local_workspace_path))
|
container.start(container_start_options(execution_environment, local_workspace_path))
|
||||||
|
container.start_time = Time.now
|
||||||
container
|
container
|
||||||
rescue Docker::Error::NotFoundError => error
|
rescue Docker::Error::NotFoundError => error
|
||||||
destroy_container(container)
|
destroy_container(container)
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
module DockerContainerMixin
|
module DockerContainerMixin
|
||||||
|
|
||||||
|
attr_accessor :start_time
|
||||||
|
attr_accessor :status
|
||||||
|
|
||||||
def binds
|
def binds
|
||||||
json['HostConfig']['Binds']
|
json['HostConfig']['Binds']
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,8 @@ require 'concurrent/timer_task'
|
|||||||
require 'concurrent/utilities'
|
require 'concurrent/utilities'
|
||||||
|
|
||||||
class DockerContainerPool
|
class DockerContainerPool
|
||||||
|
TIME_TILL_RESTART = 900
|
||||||
|
|
||||||
@containers = ThreadSafe::Hash[ExecutionEnvironment.all.map { |execution_environment| [execution_environment.id, ThreadSafe::Array.new] }]
|
@containers = ThreadSafe::Hash[ExecutionEnvironment.all.map { |execution_environment| [execution_environment.id, ThreadSafe::Array.new] }]
|
||||||
#as containers are not containing containers in use
|
#as containers are not containing containers in use
|
||||||
@all_containers = ThreadSafe::Hash[ExecutionEnvironment.all.map { |execution_environment| [execution_environment.id, ThreadSafe::Array.new] }]
|
@all_containers = ThreadSafe::Hash[ExecutionEnvironment.all.map { |execution_environment| [execution_environment.id, ThreadSafe::Array.new] }]
|
||||||
@ -22,12 +24,28 @@ class DockerContainerPool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.return_container(container, execution_environment)
|
def self.return_container(container, execution_environment)
|
||||||
|
container.status = 'available'
|
||||||
@containers[execution_environment.id].push(container)
|
@containers[execution_environment.id].push(container)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_container(execution_environment)
|
def self.get_container(execution_environment)
|
||||||
if config[:active]
|
if config[:active]
|
||||||
@containers[execution_environment.id].try(:shift) || nil
|
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]
|
||||||
|
|
||||||
|
# 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]
|
||||||
|
end
|
||||||
|
container.status = 'used'
|
||||||
|
container
|
||||||
|
|
||||||
else
|
else
|
||||||
create_container(execution_environment)
|
create_container(execution_environment)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user