From 2404c1c36c8ab3615d03ca1d76ecd53964c1d887 Mon Sep 17 00:00:00 2001 From: Konrad Hanff Date: Wed, 7 Apr 2021 17:12:26 +0200 Subject: [PATCH] Rename variables from container to runner --- app/controllers/submissions_controller.rb | 12 +++++------ app/models/submission.rb | 26 +++++++++++------------ config/code_ocean.yml.example | 2 ++ lib/runner/runner.rb | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 9f5b7a9d..34ad6f53 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -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 diff --git a/app/models/submission.rb b/app/models/submission.rb index 6256b446..90addbf8 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -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) diff --git a/config/code_ocean.yml.example b/config/code_ocean.yml.example index 72f7ed84..eb152f8f 100644 --- a/config/code_ocean.yml.example +++ b/config/code_ocean.yml.example @@ -21,6 +21,8 @@ development: url: https://codeharbor.openhpi.de prometheus_exporter: enabled: false + runner_management: + url: https://runners.example.org production: <<: *default diff --git a/lib/runner/runner.rb b/lib/runner/runner.rb index d8ae60b8..e304a7df 100644 --- a/lib/runner/runner.rb +++ b/lib/runner/runner.rb @@ -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