changed position of saving the run output, so it catches timeouts as well

This commit is contained in:
Ralf Teusner
2017-03-23 14:12:26 +01:00
parent a142e1c73f
commit 0930cba095

View File

@ -143,7 +143,7 @@ class SubmissionsController < ApplicationController
tubesock.onmessage do |data|
Rails.logger.info(Time.now.getutc.to_s + ": Client sending: " + data)
# Check whether the client send a JSON command and kill container
# if the command is 'client_exit', send it to docker otherwise.
# if the command is 'client_kill', send it to docker otherwise.
begin
parsed = JSON.parse(data)
if parsed['cmd'] == 'client_kill'
@ -170,6 +170,9 @@ class SubmissionsController < ApplicationController
end
def kill_socket(tubesock)
# save the output of this "run" as a "testrun" (scoring runs are saved in submission_scoring.rb)
save_run_output
# Hijacked connection needs to be notified correctly
tubesock.send_data JSON.dump({'cmd' => 'exit'})
tubesock.close
@ -238,6 +241,12 @@ class SubmissionsController < ApplicationController
end
end
def save_run_output
if !@message_buffer.blank?
Testrun.create(file: @file, submission: @submission, output: @message_buffer)
end
end
def score
hijack do |tubesock|
Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?