diff --git a/app/models/runner.rb b/app/models/runner.rb index 7c812307..08e84642 100644 --- a/app/models/runner.rb +++ b/app/models/runner.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'runner/runner_connection' - class Runner < ApplicationRecord BASE_URL = CodeOcean::Config.new(:code_ocean).read[:runner_management][:url] HEADERS = {'Content-Type' => 'application/json'}.freeze @@ -18,7 +16,7 @@ class Runner < ApplicationRecord def self.for(user, exercise) execution_environment = ExecutionEnvironment.find(exercise.execution_environment_id) - runner = Runner.find_or_create_by(user: user, execution_environment: execution_environment) + runner = find_or_create_by(user: user, execution_environment: execution_environment) return runner if runner.save @@ -51,7 +49,7 @@ class Runner < ApplicationRecord starting_time = Time.zone.now websocket_url = execute_command(command)[:websocketUrl] EventMachine.run do - socket = RunnerConnection.new(websocket_url) + socket = Runner::Connection.new(websocket_url) yield(self, socket) if block_given? end Time.zone.now - starting_time # execution time @@ -70,7 +68,7 @@ class Runner < ApplicationRecord def new_runner url = "#{BASE_URL}/runners" - time_limit = CodeOcean::Config.new(:code_ocean)[:runner_management][:unused_runner_expiration_time] + time_limit = CodeOcean::Config.new(:code_ocean).read[:runner_management][:unused_runner_expiration_time] body = {executionEnvironmentId: execution_environment.id, timeLimit: time_limit} response = Faraday.post(url, body.to_json, HEADERS) response_body = parse response diff --git a/config/code_ocean.yml.ci b/config/code_ocean.yml.ci index 8c0e14a8..6865a478 100644 --- a/config/code_ocean.yml.ci +++ b/config/code_ocean.yml.ci @@ -11,5 +11,4 @@ test: enabled: false runner_management: url: https://runners.example.org - cleanup_interval: 60 unused_runner_expiration_time: 180 diff --git a/config/code_ocean.yml.example b/config/code_ocean.yml.example index b2413754..f948ac6a 100644 --- a/config/code_ocean.yml.example +++ b/config/code_ocean.yml.example @@ -4,27 +4,25 @@ default: &default answers_per_query: 3 code_pilot: enabled: false + url: //localhost:3000 codeharbor: enabled: false codeocean_events: enabled: false + prometheus_exporter: + enabled: false runner_management: url: https://runners.example.org - cleanup_interval: 60 unused_runner_expiration_time: 180 development: + <<: *default flowr: enabled: true answers_per_query: 3 - code_pilot: - enabled: false - url: //localhost:3000 codeharbor: enabled: true url: https://codeharbor.openhpi.de - prometheus_exporter: - enabled: false production: <<: *default @@ -33,5 +31,3 @@ production: test: <<: *default - prometheus_exporter: - enabled: false diff --git a/lib/runner/runner_connection.rb b/lib/runner/connection.rb similarity index 98% rename from lib/runner/runner_connection.rb rename to lib/runner/connection.rb index 2aae3b45..ea3840a6 100644 --- a/lib/runner/runner_connection.rb +++ b/lib/runner/connection.rb @@ -3,7 +3,7 @@ require 'faye/websocket/client' require 'json_schemer' -class RunnerConnection +class Runner::Connection EVENTS = %i[start output exit stdout stderr].freeze BACKEND_OUTPUT_SCHEMA = JSONSchemer.schema(JSON.parse(File.read('lib/runner/backend-output.schema.json')))