Auto-correct linting issues
This commit is contained in:

committed by
Sebastian Serth

parent
6e9562c9e1
commit
80932c0c40
@ -2,24 +2,22 @@
|
||||
|
||||
class Runner
|
||||
BASE_URL = CodeOcean::Config.new(:code_ocean).read[:container_management][:url]
|
||||
HEADERS = {"Content-Type" => "application/json"}
|
||||
HEADERS = {'Content-Type' => 'application/json'}.freeze
|
||||
|
||||
attr_accessor :waiting_time
|
||||
|
||||
def initialize(execution_environment, time_limit = nil)
|
||||
url = "#{BASE_URL}/runners"
|
||||
body = {executionEnvironmentId: execution_environment.id}
|
||||
if time_limit
|
||||
body[:timeLimit] = time_limit
|
||||
end
|
||||
body[:timeLimit] = time_limit if time_limit
|
||||
response = Faraday.post(url, body.to_json, HEADERS)
|
||||
response = parse response
|
||||
@id = response[:runnerId]
|
||||
end
|
||||
|
||||
def copy_files(files)
|
||||
url = runner_url + "/files"
|
||||
body = { files: files.map { |filename, content| { filepath: filename, content: content } } }
|
||||
url = "#{runner_url}/files"
|
||||
body = {files: files.map { |filename, content| {filepath: filename, content: content} }}
|
||||
Faraday.patch(url, body.to_json, HEADERS)
|
||||
end
|
||||
|
||||
@ -32,20 +30,19 @@ class Runner
|
||||
end
|
||||
|
||||
def execute_command(command)
|
||||
url = runner_url + "/execute"
|
||||
url = "#{runner_url}/execute"
|
||||
response = Faraday.post(url, {command: command}.to_json, HEADERS)
|
||||
response = parse response
|
||||
response
|
||||
parse response
|
||||
end
|
||||
|
||||
def execute_interactively(command)
|
||||
starting_time = Time.now
|
||||
starting_time = Time.zone.now
|
||||
websocket_url = execute_command(command)[:websocketUrl]
|
||||
EventMachine.run do
|
||||
socket = RunnerConnection.new(websocket_url)
|
||||
yield(self, socket) if block_given?
|
||||
end
|
||||
Time.now - starting_time # execution time
|
||||
Time.zone.now - starting_time # execution time
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
@ -1,19 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'faye/websocket/client'
|
||||
require 'json_schemer'
|
||||
|
||||
class RunnerConnection
|
||||
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')))
|
||||
|
||||
def initialize(url)
|
||||
@socket = Faye::WebSocket::Client.new(url, [], ping: 5)
|
||||
|
||||
%i[open message error close].each do |event_type|
|
||||
@socket.on event_type do |event| __send__(:"on_#{event_type}", event) end
|
||||
@socket.on(event_type) { |event| __send__(:"on_#{event_type}", event) }
|
||||
end
|
||||
|
||||
EVENTS.each { |event_type| instance_variable_set(:"@#{event_type}_callback", lambda {|e|}) }
|
||||
@start_callback = lambda {}
|
||||
EVENTS.each { |event_type| instance_variable_set(:"@#{event_type}_callback", ->(e) {}) }
|
||||
@start_callback = -> {}
|
||||
@exit_code = 0
|
||||
end
|
||||
|
||||
@ -42,7 +44,7 @@ class RunnerConnection
|
||||
|
||||
event = decode(event.data)
|
||||
|
||||
# TODO handle other events like timeout
|
||||
# TODO: handle other events like timeout
|
||||
case event[:type].to_sym
|
||||
when :exit_code
|
||||
@exit_code = event[:data]
|
||||
@ -57,14 +59,13 @@ class RunnerConnection
|
||||
end
|
||||
end
|
||||
|
||||
def on_open(event)
|
||||
def on_open(_event)
|
||||
@start_callback.call
|
||||
end
|
||||
|
||||
def on_error(event)
|
||||
end
|
||||
def on_error(event); end
|
||||
|
||||
def on_close(event)
|
||||
def on_close(_event)
|
||||
@exit_callback.call @exit_code
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user