Generalize method and constant names for runner management
This commit is contained in:
@@ -7,9 +7,6 @@ class ExecutionEnvironment < ApplicationRecord
|
||||
include DefaultValues
|
||||
|
||||
VALIDATION_COMMAND = 'whoami'
|
||||
RUNNER_MANAGEMENT_PRESENT = CodeOcean::Config.new(:code_ocean).read[:runner_management].present?
|
||||
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:runner_management][:url] if RUNNER_MANAGEMENT_PRESENT
|
||||
HEADERS = {'Content-Type' => 'application/json'}.freeze
|
||||
DEFAULT_CPU_LIMIT = 20
|
||||
|
||||
after_initialize :set_default_values
|
||||
@@ -42,20 +39,6 @@ class ExecutionEnvironment < ApplicationRecord
|
||||
name
|
||||
end
|
||||
|
||||
def copy_to_poseidon
|
||||
return false unless RUNNER_MANAGEMENT_PRESENT
|
||||
|
||||
url = "#{BASE_URL}/execution-environments/#{id}"
|
||||
response = Faraday.put(url, to_json, HEADERS)
|
||||
return true if [201, 204].include? response.status
|
||||
|
||||
Rails.logger.warn("Could not create execution environment in Poseidon, got response: #{response.as_json}")
|
||||
false
|
||||
rescue Faraday::Error => e
|
||||
Rails.logger.warn("Could not create execution environment because of Faraday error: #{e.inspect}")
|
||||
false
|
||||
end
|
||||
|
||||
def to_json(*_args)
|
||||
{
|
||||
id: id,
|
||||
|
@@ -8,14 +8,15 @@ class Runner < ApplicationRecord
|
||||
|
||||
validates :execution_environment, :user, :runner_id, presence: true
|
||||
|
||||
STRATEGY_NAME = CodeOcean::Config.new(:code_ocean).read[:runner_management][:strategy]
|
||||
UNUSED_EXPIRATION_TIME = CodeOcean::Config.new(:code_ocean).read[:runner_management][:unused_runner_expiration_time].seconds
|
||||
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:runner_management][:url]
|
||||
|
||||
attr_accessor :strategy
|
||||
|
||||
def self.strategy_class
|
||||
"runner/strategy/#{STRATEGY_NAME}".camelize.constantize
|
||||
strategy_name = CodeOcean::Config.new(:code_ocean).read[:runner_management][:strategy]
|
||||
@strategy_class ||= "runner/strategy/#{strategy_name}".camelize.constantize
|
||||
end
|
||||
|
||||
def self.management_active?
|
||||
@management_active ||= CodeOcean::Config.new(:code_ocean).read[:runner_management][:enabled]
|
||||
end
|
||||
|
||||
def self.for(user, exercise)
|
||||
|
Reference in New Issue
Block a user