Restructure methods in execution_environment.rb
This commit is contained in:
@ -19,8 +19,9 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
|
|
||||||
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }
|
scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') }
|
||||||
|
|
||||||
|
before_validation :clean_exposed_ports
|
||||||
|
|
||||||
validate :valid_test_setup?
|
validate :valid_test_setup?
|
||||||
validate :working_docker_image?, if: :validate_docker_image?
|
|
||||||
validates :docker_image, presence: true
|
validates :docker_image, presence: true
|
||||||
validates :memory_limit,
|
validates :memory_limit,
|
||||||
numericality: {greater_than_or_equal_to: MINIMUM_MEMORY_LIMIT, only_integer: true}, presence: true
|
numericality: {greater_than_or_equal_to: MINIMUM_MEMORY_LIMIT, only_integer: true}, presence: true
|
||||||
@ -30,7 +31,6 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
validates :pool_size, numericality: {only_integer: true}, presence: true
|
validates :pool_size, numericality: {only_integer: true}, presence: true
|
||||||
validates :run_command, presence: true
|
validates :run_command, presence: true
|
||||||
validates :cpu_limit, presence: true, numericality: {greater_than: 0, only_integer: true}
|
validates :cpu_limit, presence: true, numericality: {greater_than: 0, only_integer: true}
|
||||||
before_validation :clean_exposed_ports
|
|
||||||
validates :exposed_ports, array: {numericality: {greater_than_or_equal_to: 0, less_than: 65_536, only_integer: true}}
|
validates :exposed_ports, array: {numericality: {greater_than_or_equal_to: 0, less_than: 65_536, only_integer: true}}
|
||||||
|
|
||||||
after_destroy :delete_runner_environment
|
after_destroy :delete_runner_environment
|
||||||
@ -59,10 +59,15 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
exposed_ports.join(', ')
|
exposed_ports.join(', ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_default_values
|
||||||
|
set_default_values_if_present(permitted_execution_time: 60, pool_size: 0)
|
||||||
|
end
|
||||||
|
|
||||||
def clean_exposed_ports
|
def clean_exposed_ports
|
||||||
self.exposed_ports = exposed_ports.uniq.sort
|
self.exposed_ports = exposed_ports.uniq.sort
|
||||||
end
|
end
|
||||||
private :clean_exposed_ports
|
|
||||||
|
|
||||||
def valid_test_setup?
|
def valid_test_setup?
|
||||||
if test_command? ^ testing_framework?
|
if test_command? ^ testing_framework?
|
||||||
@ -71,12 +76,10 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
attribute: I18n.t('activerecord.attributes.execution_environment.testing_framework')))
|
attribute: I18n.t('activerecord.attributes.execution_environment.testing_framework')))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private :valid_test_setup?
|
|
||||||
|
|
||||||
def validate_docker_image?
|
def validate_docker_image?
|
||||||
docker_image.present? && !Rails.env.test?
|
docker_image.present? && !Rails.env.test?
|
||||||
end
|
end
|
||||||
private :validate_docker_image?
|
|
||||||
|
|
||||||
def working_docker_image?
|
def working_docker_image?
|
||||||
sync_runner_environment
|
sync_runner_environment
|
||||||
|
Reference in New Issue
Block a user