Move RunnerConnection into class Runner
The old approach was to require the runner connection. This did not work anymore with Zeitwerk in Rails 6. @sebastian.serth and I moved the Connection class in `lib` into the ActiveRecord class `Runner`. This will also work with future changes like specific error classes. Furthermore the config was fixed and simplified. Co-authored-by: Sebastian Serth <Sebastian.Serth@hpi.de>
This commit is contained in:

committed by
Sebastian Serth

parent
63d997a7e3
commit
8d968e01e6
@ -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
|
||||
|
@ -11,5 +11,4 @@ test:
|
||||
enabled: false
|
||||
runner_management:
|
||||
url: https://runners.example.org
|
||||
cleanup_interval: 60
|
||||
unused_runner_expiration_time: 180
|
||||
|
@ -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
|
||||
|
@ -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')))
|
||||
|
Reference in New Issue
Block a user