Forward input as raw_event to runner
* Also, rename #send to #send_data in order to prevent debugging issues in RubyMine
This commit is contained in:
@ -95,21 +95,23 @@ class SubmissionsController < ApplicationController
|
|||||||
runner_socket&.close(:terminated_by_client)
|
runner_socket&.close(:terminated_by_client)
|
||||||
end
|
end
|
||||||
|
|
||||||
client_socket.onmessage do |event|
|
client_socket.onmessage do |raw_event|
|
||||||
event = JSON.parse(event).deep_symbolize_keys
|
event = JSON.parse(raw_event).deep_symbolize_keys
|
||||||
case event[:cmd].to_sym
|
case event[:cmd].to_sym
|
||||||
when :client_kill
|
when :client_kill
|
||||||
close_client_connection(client_socket)
|
close_client_connection(client_socket)
|
||||||
Rails.logger.debug('Client exited container.')
|
Rails.logger.debug('Client exited container.')
|
||||||
when :result
|
when :result, :canvasevent, :exception
|
||||||
# The client cannot send something before the runner connection is established.
|
# The client cannot send something before the runner connection is established.
|
||||||
if runner_socket.present?
|
if runner_socket.present?
|
||||||
runner_socket.send event[:data]
|
runner_socket.send_data raw_event
|
||||||
else
|
else
|
||||||
Rails.logger.info("Could not forward data from client because runner connection was not established yet: #{event[:data].inspect}")
|
Rails.logger.info("Could not forward data from client because runner connection was not established yet: #{event[:data].inspect}")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
|
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
|
||||||
|
Sentry.set_extras(event: event)
|
||||||
|
Sentry.capture_message("Unknown command from client: #{event[:cmd]}")
|
||||||
end
|
end
|
||||||
rescue JSON::ParserError => e
|
rescue JSON::ParserError => e
|
||||||
Rails.logger.info("Data received from client is not valid json: #{data.inspect}")
|
Rails.logger.info("Data received from client is not valid json: #{data.inspect}")
|
||||||
|
@ -43,7 +43,7 @@ class Runner::Connection
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Send arbitrary data in the WebSocket connection
|
# Send arbitrary data in the WebSocket connection
|
||||||
def send(raw_data)
|
def send_data(raw_data)
|
||||||
encoded_message = encode(raw_data)
|
encoded_message = encode(raw_data)
|
||||||
Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" }
|
Rails.logger.debug { "#{Time.zone.now.getutc}: Sending to #{@socket.url}: #{encoded_message.inspect}" }
|
||||||
@socket.send(encoded_message)
|
@socket.send(encoded_message)
|
||||||
|
@ -64,7 +64,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
|
|||||||
socket = Connection.new(websocket_url, self, event_loop)
|
socket = Connection.new(websocket_url, self, event_loop)
|
||||||
begin
|
begin
|
||||||
Timeout.timeout(@execution_environment.permitted_execution_time) do
|
Timeout.timeout(@execution_environment.permitted_execution_time) do
|
||||||
socket.send(command)
|
socket.send_data(command)
|
||||||
yield(socket)
|
yield(socket)
|
||||||
event_loop.wait
|
event_loop.wait
|
||||||
event_loop.stop
|
event_loop.stop
|
||||||
|
Reference in New Issue
Block a user