From 79da2781e31e2f9f9ac69c7434d0ba404c31f82a Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 4 Nov 2021 01:05:28 +0100 Subject: [PATCH] Restructure methods in execution_environment.rb --- app/models/execution_environment.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/execution_environment.rb b/app/models/execution_environment.rb index b5f16157..1b3342e5 100644 --- a/app/models/execution_environment.rb +++ b/app/models/execution_environment.rb @@ -19,8 +19,9 @@ class ExecutionEnvironment < ApplicationRecord scope :with_exercises, -> { where('id IN (SELECT execution_environment_id FROM exercises)') } + before_validation :clean_exposed_ports + validate :valid_test_setup? - validate :working_docker_image?, if: :validate_docker_image? validates :docker_image, presence: true validates :memory_limit, 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 :run_command, presence: 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}} after_destroy :delete_runner_environment @@ -59,10 +59,15 @@ class ExecutionEnvironment < ApplicationRecord exposed_ports.join(', ') end + private + + def set_default_values + set_default_values_if_present(permitted_execution_time: 60, pool_size: 0) + end + def clean_exposed_ports self.exposed_ports = exposed_ports.uniq.sort end - private :clean_exposed_ports def valid_test_setup? if test_command? ^ testing_framework? @@ -71,12 +76,10 @@ class ExecutionEnvironment < ApplicationRecord attribute: I18n.t('activerecord.attributes.execution_environment.testing_framework'))) end end - private :valid_test_setup? def validate_docker_image? docker_image.present? && !Rails.env.test? end - private :validate_docker_image? def working_docker_image? sync_runner_environment