Allow editing an Execution Environment with active runner management
This commit is contained in:
@ -76,10 +76,10 @@ class ExecutionEnvironment < ApplicationRecord
|
|||||||
private :validate_docker_image?
|
private :validate_docker_image?
|
||||||
|
|
||||||
def working_docker_image?
|
def working_docker_image?
|
||||||
DockerClient.pull(docker_image) if DockerClient.find_image_by_tag(docker_image).present?
|
runner = Runner.for(author, self)
|
||||||
output = DockerClient.new(execution_environment: self).execute_arbitrary_command(VALIDATION_COMMAND)
|
output = runner.execute_command(VALIDATION_COMMAND, raise_exception: true)
|
||||||
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
||||||
rescue DockerClient::Error => e
|
rescue Runner::Error => e
|
||||||
errors.add(:docker_image, "error: #{e}")
|
errors.add(:docker_image, "error: #{e}")
|
||||||
end
|
end
|
||||||
private :working_docker_image?
|
private :working_docker_image?
|
||||||
|
@ -60,7 +60,7 @@ class Runner < ApplicationRecord
|
|||||||
Time.zone.now - starting_time # execution duration
|
Time.zone.now - starting_time # execution duration
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_command(command)
|
def execute_command(command, raise_exception: false)
|
||||||
output = {}
|
output = {}
|
||||||
stdout = +''
|
stdout = +''
|
||||||
stderr = +''
|
stderr = +''
|
||||||
@ -95,6 +95,9 @@ class Runner < ApplicationRecord
|
|||||||
Rails.logger.debug { "Running command `#{command}` failed: #{e.message}" }
|
Rails.logger.debug { "Running command `#{command}` failed: #{e.message}" }
|
||||||
output.merge!(status: :failed, container_execution_time: e.execution_duration)
|
output.merge!(status: :failed, container_execution_time: e.execution_duration)
|
||||||
ensure
|
ensure
|
||||||
|
# We forward the exception if requested
|
||||||
|
raise e if raise_exception && defined?(e) && e.present?
|
||||||
|
|
||||||
output.merge!(stdout: stdout, stderr: stderr)
|
output.merge!(stdout: stdout, stderr: stderr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user