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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'runner/runner_connection'
|
|
||||||
|
|
||||||
class Runner < ApplicationRecord
|
class Runner < ApplicationRecord
|
||||||
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:runner_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
|
||||||
@ -18,7 +16,7 @@ class Runner < ApplicationRecord
|
|||||||
|
|
||||||
def self.for(user, exercise)
|
def self.for(user, exercise)
|
||||||
execution_environment = ExecutionEnvironment.find(exercise.execution_environment_id)
|
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
|
return runner if runner.save
|
||||||
|
|
||||||
@ -51,7 +49,7 @@ class Runner < ApplicationRecord
|
|||||||
starting_time = Time.zone.now
|
starting_time = Time.zone.now
|
||||||
websocket_url = execute_command(command)[:websocketUrl]
|
websocket_url = execute_command(command)[:websocketUrl]
|
||||||
EventMachine.run do
|
EventMachine.run do
|
||||||
socket = RunnerConnection.new(websocket_url)
|
socket = Runner::Connection.new(websocket_url)
|
||||||
yield(self, socket) if block_given?
|
yield(self, socket) if block_given?
|
||||||
end
|
end
|
||||||
Time.zone.now - starting_time # execution time
|
Time.zone.now - starting_time # execution time
|
||||||
@ -70,7 +68,7 @@ class Runner < ApplicationRecord
|
|||||||
|
|
||||||
def new_runner
|
def new_runner
|
||||||
url = "#{BASE_URL}/runners"
|
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}
|
body = {executionEnvironmentId: execution_environment.id, timeLimit: time_limit}
|
||||||
response = Faraday.post(url, body.to_json, HEADERS)
|
response = Faraday.post(url, body.to_json, HEADERS)
|
||||||
response_body = parse response
|
response_body = parse response
|
||||||
|
@ -11,5 +11,4 @@ test:
|
|||||||
enabled: false
|
enabled: false
|
||||||
runner_management:
|
runner_management:
|
||||||
url: https://runners.example.org
|
url: https://runners.example.org
|
||||||
cleanup_interval: 60
|
|
||||||
unused_runner_expiration_time: 180
|
unused_runner_expiration_time: 180
|
||||||
|
@ -4,27 +4,25 @@ default: &default
|
|||||||
answers_per_query: 3
|
answers_per_query: 3
|
||||||
code_pilot:
|
code_pilot:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
url: //localhost:3000
|
||||||
codeharbor:
|
codeharbor:
|
||||||
enabled: false
|
enabled: false
|
||||||
codeocean_events:
|
codeocean_events:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
prometheus_exporter:
|
||||||
|
enabled: false
|
||||||
runner_management:
|
runner_management:
|
||||||
url: https://runners.example.org
|
url: https://runners.example.org
|
||||||
cleanup_interval: 60
|
|
||||||
unused_runner_expiration_time: 180
|
unused_runner_expiration_time: 180
|
||||||
|
|
||||||
development:
|
development:
|
||||||
|
<<: *default
|
||||||
flowr:
|
flowr:
|
||||||
enabled: true
|
enabled: true
|
||||||
answers_per_query: 3
|
answers_per_query: 3
|
||||||
code_pilot:
|
|
||||||
enabled: false
|
|
||||||
url: //localhost:3000
|
|
||||||
codeharbor:
|
codeharbor:
|
||||||
enabled: true
|
enabled: true
|
||||||
url: https://codeharbor.openhpi.de
|
url: https://codeharbor.openhpi.de
|
||||||
prometheus_exporter:
|
|
||||||
enabled: false
|
|
||||||
|
|
||||||
production:
|
production:
|
||||||
<<: *default
|
<<: *default
|
||||||
@ -33,5 +31,3 @@ production:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
<<: *default
|
<<: *default
|
||||||
prometheus_exporter:
|
|
||||||
enabled: false
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
require 'faye/websocket/client'
|
require 'faye/websocket/client'
|
||||||
require 'json_schemer'
|
require 'json_schemer'
|
||||||
|
|
||||||
class RunnerConnection
|
class Runner::Connection
|
||||||
EVENTS = %i[start output exit stdout stderr].freeze
|
EVENTS = %i[start output exit stdout stderr].freeze
|
||||||
BACKEND_OUTPUT_SCHEMA = JSONSchemer.schema(JSON.parse(File.read('lib/runner/backend-output.schema.json')))
|
BACKEND_OUTPUT_SCHEMA = JSONSchemer.schema(JSON.parse(File.read('lib/runner/backend-output.schema.json')))
|
||||||
|
|
Reference in New Issue
Block a user