Add release and pool_size methods to DCP
This commit is contained in:
@ -7,8 +7,15 @@ module Admin
|
||||
end
|
||||
|
||||
def docker_data
|
||||
pool_size = begin
|
||||
Runner.strategy_class.pool_size
|
||||
rescue Runner::Error => e
|
||||
Rails.logger.debug { "Runner error while fetching current pool size: #{e.message}" }
|
||||
[]
|
||||
end
|
||||
|
||||
ExecutionEnvironment.order(:id).select(:id, :pool_size).map do |execution_environment|
|
||||
execution_environment.attributes.merge(quantity: DockerContainerPool.quantities[execution_environment.id])
|
||||
execution_environment.attributes.merge(quantity: pool_size[execution_environment.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -100,11 +100,24 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
||||
end
|
||||
|
||||
def self.release
|
||||
nil
|
||||
url = "#{config[:pool][:location]}/docker_container_pool/dump_info"
|
||||
response = Faraday.get(url)
|
||||
JSON.parse(response.body)['release']
|
||||
rescue Faraday::Error => e
|
||||
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
|
||||
rescue JSON::ParserError => e
|
||||
raise Runner::Error::UnexpectedResponse.new("DockerContainerPool returned invalid JSON: #{e.inspect}")
|
||||
end
|
||||
|
||||
def self.pool_size
|
||||
{}
|
||||
url = "#{config[:pool][:location]}/docker_container_pool/quantities"
|
||||
response = Faraday.get(url)
|
||||
pool_size = JSON.parse(response.body)
|
||||
pool_size.transform_keys(&:to_i)
|
||||
rescue Faraday::Error => e
|
||||
raise Runner::Error::FaradayError.new("Request to DockerContainerPool failed: #{e.inspect}")
|
||||
rescue JSON::ParserError => e
|
||||
raise Runner::Error::UnexpectedResponse.new("DockerContainerPool returned invalid JSON: #{e.inspect}")
|
||||
end
|
||||
|
||||
def self.websocket_header
|
||||
|
@ -10,7 +10,12 @@ describe Admin::DashboardHelper do
|
||||
end
|
||||
|
||||
describe '#docker_data' do
|
||||
before { FactoryBot.create(:ruby) }
|
||||
before do
|
||||
FactoryBot.create(:ruby)
|
||||
dcp = instance_double 'docker_container_pool'
|
||||
allow(Runner).to receive(:strategy_class).and_return dcp
|
||||
allow(dcp).to receive(:pool_size).and_return([])
|
||||
end
|
||||
|
||||
it 'contains an entry for every execution environment' do
|
||||
expect(docker_data.length).to eq(ExecutionEnvironment.count)
|
||||
@ -21,7 +26,6 @@ describe Admin::DashboardHelper do
|
||||
end
|
||||
|
||||
it 'contains the number of available containers for every execution environment' do
|
||||
expect(DockerContainerPool).to receive(:quantities).exactly(ExecutionEnvironment.count).times.and_call_original
|
||||
expect(docker_data.first).to include(:quantity)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user