fixed saving run results. also fixed websocket closing.

This commit is contained in:
Ralf Teusner
2017-03-24 18:47:30 +01:00
parent 5aeda988b7
commit bdbc372c0c
2 changed files with 14 additions and 5 deletions

View File

@ -182,12 +182,13 @@ class SubmissionsController < ApplicationController
@message_buffer ||= "" @message_buffer ||= ""
# Handle special commands first # Handle special commands first
if (/^#exit/.match(message)) if (/^#exit/.match(message))
kill_socket(tubesock) # Just call exit_container on the docker_client.
# Do not call kill_socket for the websocket to the client here.
# @docker_client.exit_container closes the socket to the container,
# kill_socket is called in the "on close handler" of the websocket to the container
@docker_client.exit_container(container) @docker_client.exit_container(container)
if !@message_buffer.blank? elsif /^#timeout/.match(message)
Testrun.create(file: @file, submission: @submission, output: @message_buffer) @message_buffer = 'timeout: ' + @message_buffer # add information that this run timed out to the buffer
end
else else
# Filter out information about run_command, test_command, user or working directory # Filter out information about run_command, test_command, user or working directory
run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename]) run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename])
@ -243,6 +244,7 @@ class SubmissionsController < ApplicationController
def save_run_output def save_run_output
if !@message_buffer.blank? if !@message_buffer.blank?
@message_buffer = @message_buffer[(0..max_message_buffer_size-1)] # trim the string to max_message_buffer_size chars
Testrun.create(file: @file, submission: @submission, output: @message_buffer) Testrun.create(file: @file, submission: @submission, output: @message_buffer)
end end
end end

View File

@ -255,6 +255,12 @@ class DockerClient
if(@tubesock) if(@tubesock)
@tubesock.send_data JSON.dump({'cmd' => 'timeout'}) @tubesock.send_data JSON.dump({'cmd' => 'timeout'})
end end
if(@socket)
@socket.send('#timeout')
#sleep one more second to ensure that the message reaches the submissions_controller.
sleep(1)
@socket.close
end
kill_container(container) kill_container(container)
end end
#ensure #ensure
@ -274,6 +280,7 @@ class DockerClient
Rails.logger.debug('exiting container ' + container.to_s) Rails.logger.debug('exiting container ' + container.to_s)
# exit the timeout thread if it is still alive # exit the timeout thread if it is still alive
exit_thread_if_alive exit_thread_if_alive
@socket.close
# if we use pooling and recylce the containers, put it back. otherwise, destroy it. # if we use pooling and recylce the containers, put it back. otherwise, destroy it.
(DockerContainerPool.config[:active] && RECYCLE_CONTAINERS) ? self.class.return_container(container, @execution_environment) : self.class.destroy_container(container) (DockerContainerPool.config[:active] && RECYCLE_CONTAINERS) ? self.class.return_container(container, @execution_environment) : self.class.destroy_container(container)
end end