Add environments method to all strategies

This commit is contained in:
Sebastian Serth
2021-11-04 10:40:01 +01:00
parent 79da2781e3
commit 054d35b8d3
4 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,10 @@ class Runner::Strategy
raise NotImplementedError
end
def self.environments
raise NotImplementedError
end
def self.sync_environment(_environment)
raise NotImplementedError
end

View File

@ -14,6 +14,10 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
FileUtils.mkdir_p(File.expand_path(config[:workspace_root]))
end
def self.environments
pool_size.keys.map {|key| {id: key} }
end
def self.sync_environment(environment)
# Force a database commit and start a new transaction.
if environment.class.connection.transaction_open?

View File

@ -5,6 +5,10 @@
class Runner::Strategy::Null < Runner::Strategy
def self.initialize_environment; end
def self.environments
raise Runner::Error.new
end
def self.sync_environment(_environment)
raise Runner::Error.new
end

View File

@ -19,6 +19,27 @@ class Runner::Strategy::Poseidon < Runner::Strategy
nil
end
def self.environments
url = "#{config[:url]}/execution-environments"
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Getting list of execution environments at #{url}" }
response = http_connection.get url
case response.status
when 200
response_body = parse response
execution_environments = response_body[:executionEnvironments]
execution_environments.presence || raise(Runner::Error::UnexpectedResponse.new("Could not get the list of execution environments in Poseidon, got response: #{response.as_json}"))
when 404
raise Runner::Error::EnvironmentNotFound.new
else
handle_error response
end
rescue Faraday::Error => e
raise Runner::Error::FaradayError.new("Could not get the list of execution environments because of Faraday error: #{e.inspect}")
ensure
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Finished getting the list of execution environments" }
end
def self.sync_environment(environment)
url = "#{config[:url]}/execution-environments/#{environment.id}"
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Synchronizing execution environment at #{url}" }