Rename variables from container to runner
This commit is contained in:

committed by
Sebastian Serth

parent
3e6534567d
commit
2404c1c36c
@ -132,7 +132,7 @@ class SubmissionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_websockets(tubesock, container, socket)
|
def handle_websockets(tubesock, runner, socket)
|
||||||
tubesock.send_data JSON.dump({'cmd' => 'status', 'status' => :container_running})
|
tubesock.send_data JSON.dump({'cmd' => 'status', 'status' => :container_running})
|
||||||
@output = String.new
|
@output = String.new
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class SubmissionsController < ApplicationController
|
|||||||
|
|
||||||
socket.on :exit do |exit_code|
|
socket.on :exit do |exit_code|
|
||||||
EventMachine.stop_event_loop
|
EventMachine.stop_event_loop
|
||||||
status = container.status
|
status = runner.status
|
||||||
if status == :timeouted
|
if status == :timeouted
|
||||||
tubesock.send_data JSON.dump({cmd: :timeout})
|
tubesock.send_data JSON.dump({cmd: :timeout})
|
||||||
@output = "timeout: #{@output}"
|
@output = "timeout: #{@output}"
|
||||||
@ -168,7 +168,7 @@ class SubmissionsController < ApplicationController
|
|||||||
when :client_kill
|
when :client_kill
|
||||||
EventMachine.stop_event_loop
|
EventMachine.stop_event_loop
|
||||||
kill_socket(tubesock)
|
kill_socket(tubesock)
|
||||||
container.destroy
|
runner.destroy
|
||||||
Rails.logger.debug('Client exited container.')
|
Rails.logger.debug('Client exited container.')
|
||||||
when :result
|
when :result
|
||||||
socket.send event[:data]
|
socket.send event[:data]
|
||||||
@ -189,9 +189,9 @@ class SubmissionsController < ApplicationController
|
|||||||
if @embed_options[:disable_run]
|
if @embed_options[:disable_run]
|
||||||
kill_socket(tubesock)
|
kill_socket(tubesock)
|
||||||
else
|
else
|
||||||
@container_execution_time = @submission.run(sanitize_filename) do |container, socket|
|
@container_execution_time = @submission.run(sanitize_filename) do |runner, socket|
|
||||||
@waiting_for_container_time = container.waiting_time
|
@waiting_for_container_time = runner.waiting_time
|
||||||
handle_websockets(tubesock, container, socket)
|
handle_websockets(tubesock, runner, socket)
|
||||||
end
|
end
|
||||||
save_run_output
|
save_run_output
|
||||||
end
|
end
|
||||||
|
@ -141,13 +141,13 @@ class Submission < ApplicationRecord
|
|||||||
|
|
||||||
def calculate_score
|
def calculate_score
|
||||||
score = nil
|
score = nil
|
||||||
prepared_container do |container|
|
prepared_runner do |runner|
|
||||||
scores = collect_files.select(&:teacher_defined_assessment?).map do |file|
|
scores = collect_files.select(&:teacher_defined_assessment?).map do |file|
|
||||||
score_command = command_for execution_environment.test_command, file.name_with_extension
|
score_command = command_for execution_environment.test_command, file.name_with_extension
|
||||||
stdout = ""
|
stdout = ""
|
||||||
stderr = ""
|
stderr = ""
|
||||||
exit_code = 1 # default to error
|
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|
|
socket.on :stderr do |data|
|
||||||
stderr << data
|
stderr << data
|
||||||
end
|
end
|
||||||
@ -161,7 +161,7 @@ class Submission < ApplicationRecord
|
|||||||
end
|
end
|
||||||
output = {
|
output = {
|
||||||
file_role: file.role,
|
file_role: file.role,
|
||||||
waiting_for_container_time: container.waiting_time,
|
waiting_for_container_time: runner.waiting_time,
|
||||||
container_execution_time: execution_time,
|
container_execution_time: execution_time,
|
||||||
status: (exit_code == 0) ? :ok : :failed,
|
status: (exit_code == 0) ? :ok : :failed,
|
||||||
stdout: stdout,
|
stdout: stdout,
|
||||||
@ -177,29 +177,29 @@ class Submission < ApplicationRecord
|
|||||||
def run(file, &block)
|
def run(file, &block)
|
||||||
run_command = command_for execution_environment.run_command, file
|
run_command = command_for execution_environment.run_command, file
|
||||||
execution_time = 0
|
execution_time = 0
|
||||||
prepared_container do |container|
|
prepared_runner do |runner|
|
||||||
execution_time = container.execute_interactively(run_command, &block)
|
execution_time = runner.execute_interactively(run_command, &block)
|
||||||
end
|
end
|
||||||
execution_time
|
execution_time
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def copy_files_to(container)
|
def copy_files_to(runner)
|
||||||
files = {}
|
files = {}
|
||||||
collect_files.each do |file|
|
collect_files.each do |file|
|
||||||
files[file.name_with_extension] = file.content
|
files[file.name_with_extension] = file.content
|
||||||
end
|
end
|
||||||
container.copy_files(files)
|
runner.copy_files(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepared_container
|
def prepared_runner
|
||||||
request_time = Time.now
|
request_time = Time.now
|
||||||
container = Runner.new(execution_environment, execution_environment.permitted_execution_time)
|
runner = Runner.new(execution_environment, execution_environment.permitted_execution_time)
|
||||||
copy_files_to container
|
copy_files_to runner
|
||||||
container.waiting_time = Time.now - request_time
|
runner.waiting_time = Time.now - request_time
|
||||||
yield(container) if block_given?
|
yield(runner) if block_given?
|
||||||
container.destroy
|
runner.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def command_for(template, file)
|
def command_for(template, file)
|
||||||
|
@ -21,6 +21,8 @@ development:
|
|||||||
url: https://codeharbor.openhpi.de
|
url: https://codeharbor.openhpi.de
|
||||||
prometheus_exporter:
|
prometheus_exporter:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
runner_management:
|
||||||
|
url: https://runners.example.org
|
||||||
|
|
||||||
production:
|
production:
|
||||||
<<: *default
|
<<: *default
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Runner
|
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
|
HEADERS = {'Content-Type' => 'application/json'}.freeze
|
||||||
|
|
||||||
attr_accessor :waiting_time
|
attr_accessor :waiting_time
|
||||||
|
Reference in New Issue
Block a user