Merge remote-tracking branch 'origin/master' into statistics

This commit is contained in:
Maximilian Grundke
2015-11-19 16:01:53 +01:00
8 changed files with 76 additions and 34 deletions

View File

@ -25,6 +25,11 @@ class SubmissionsController < ApplicationController
create_and_respond(object: @submission)
end
def command_substitutions(filename)
{class_name: File.basename(filename, File.extname(filename)).camelize, filename: filename, module_name: File.basename(filename, File.extname(filename)).underscore}
end
private :command_substitutions
def copy_comments
# copy each annotation and set the target_file.id
unless(params[:annotations_arr].nil?)
@ -88,6 +93,11 @@ class SubmissionsController < ApplicationController
# end
hijack do |tubesock|
# probably add:
# ensure
# #guarantee that the thread is releasing the DB connection after it is done
# ActiveRecord::Base.connectionpool.releaseconnection
# end
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
@ -103,7 +113,7 @@ class SubmissionsController < ApplicationController
socket = result[:socket]
socket.on :message do |event|
Rails.logger.info("Docker sending: " + event.data)
Rails.logger.info( Time.now.getutc.to_s + ": Docker sending: " + event.data)
handle_message(event.data, tubesock)
end
@ -112,7 +122,7 @@ class SubmissionsController < ApplicationController
end
tubesock.onmessage do |data|
Rails.logger.debug("Client sending: " + data)
Rails.logger.info(Time.now.getutc.to_s + ": Client sending: " + data)
# Check wether the client send a JSON command and kill container
# if the command is 'exit', send it to docker otherwise.
begin
@ -122,9 +132,11 @@ class SubmissionsController < ApplicationController
@docker_client.exit_container(result[:container])
else
socket.send data
Rails.logger.debug('Sent the received client data to docker:' + data)
end
rescue JSON::ParserError
socket.send data
Rails.logger.debug('Rescued parsing error, sent the received client data to docker:' + data)
end
end
else
@ -145,8 +157,8 @@ class SubmissionsController < ApplicationController
kill_socket(tubesock)
else
# Filter out information about run_command, test_command, user or working directory
run_command = @submission.execution_environment.run_command
test_command = @submission.execution_environment.test_command
run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename])
test_command = @submission.execution_environment.test_command % command_substitutions(params[:filename])
if !(/root|workspace|#{run_command}|#{test_command}/.match(message))
parse_message(message, 'stdout', tubesock)
end
@ -157,6 +169,7 @@ class SubmissionsController < ApplicationController
begin
parsed = JSON.parse(message)
socket.send_data message
Rails.logger.info('parse_message sent: ' + message)
rescue JSON::ParserError => e
# Check wether the message contains multiple lines, if true try to parse each line
if ((recursive == true) && (message.include? "\n"))
@ -166,6 +179,7 @@ class SubmissionsController < ApplicationController
else
parsed = {'cmd'=>'write','stream'=>output_stream,'data'=>message}
socket.send_data JSON.dump(parsed)
Rails.logger.info('parse_message sent: ' + JSON.dump(parsed))
end
end
end