Rename variables from container to runner

This commit is contained in:
Konrad Hanff
2021-04-07 17:12:26 +02:00
committed by Sebastian Serth
parent 3e6534567d
commit 2404c1c36c
4 changed files with 22 additions and 20 deletions

View File

@ -132,7 +132,7 @@ class SubmissionsController < ApplicationController
end
end
def handle_websockets(tubesock, container, socket)
def handle_websockets(tubesock, runner, socket)
tubesock.send_data JSON.dump({'cmd' => 'status', 'status' => :container_running})
@output = String.new
@ -151,7 +151,7 @@ class SubmissionsController < ApplicationController
socket.on :exit do |exit_code|
EventMachine.stop_event_loop
status = container.status
status = runner.status
if status == :timeouted
tubesock.send_data JSON.dump({cmd: :timeout})
@output = "timeout: #{@output}"
@ -168,7 +168,7 @@ class SubmissionsController < ApplicationController
when :client_kill
EventMachine.stop_event_loop
kill_socket(tubesock)
container.destroy
runner.destroy
Rails.logger.debug('Client exited container.')
when :result
socket.send event[:data]
@ -189,9 +189,9 @@ class SubmissionsController < ApplicationController
if @embed_options[:disable_run]
kill_socket(tubesock)
else
@container_execution_time = @submission.run(sanitize_filename) do |container, socket|
@waiting_for_container_time = container.waiting_time
handle_websockets(tubesock, container, socket)
@container_execution_time = @submission.run(sanitize_filename) do |runner, socket|
@waiting_for_container_time = runner.waiting_time
handle_websockets(tubesock, runner, socket)
end
save_run_output
end

View File

@ -141,13 +141,13 @@ class Submission < ApplicationRecord
def calculate_score
score = nil
prepared_container do |container|
prepared_runner do |runner|
scores = collect_files.select(&:teacher_defined_assessment?).map do |file|
score_command = command_for execution_environment.test_command, file.name_with_extension
stdout = ""
stderr = ""
exit_code = 1 # default to error
execution_time = container.execute_interactively(score_command) do |container, socket|
execution_time = runner.execute_interactively(score_command) do |runner, socket|
socket.on :stderr do |data|
stderr << data
end
@ -161,7 +161,7 @@ class Submission < ApplicationRecord
end
output = {
file_role: file.role,
waiting_for_container_time: container.waiting_time,
waiting_for_container_time: runner.waiting_time,
container_execution_time: execution_time,
status: (exit_code == 0) ? :ok : :failed,
stdout: stdout,
@ -177,29 +177,29 @@ class Submission < ApplicationRecord
def run(file, &block)
run_command = command_for execution_environment.run_command, file
execution_time = 0
prepared_container do |container|
execution_time = container.execute_interactively(run_command, &block)
prepared_runner do |runner|
execution_time = runner.execute_interactively(run_command, &block)
end
execution_time
end
private
def copy_files_to(container)
def copy_files_to(runner)
files = {}
collect_files.each do |file|
files[file.name_with_extension] = file.content
end
container.copy_files(files)
runner.copy_files(files)
end
def prepared_container
def prepared_runner
request_time = Time.now
container = Runner.new(execution_environment, execution_environment.permitted_execution_time)
copy_files_to container
container.waiting_time = Time.now - request_time
yield(container) if block_given?
container.destroy
runner = Runner.new(execution_environment, execution_environment.permitted_execution_time)
copy_files_to runner
runner.waiting_time = Time.now - request_time
yield(runner) if block_given?
runner.destroy
end
def command_for(template, file)

View File

@ -21,6 +21,8 @@ development:
url: https://codeharbor.openhpi.de
prometheus_exporter:
enabled: false
runner_management:
url: https://runners.example.org
production:
<<: *default

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
class Runner
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:container_management][:url]
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:runner_management][:url]
HEADERS = {'Content-Type' => 'application/json'}.freeze
attr_accessor :waiting_time