Fixed container-ending on exit.
This commit is contained in:
@ -129,7 +129,7 @@ class SubmissionsController < ApplicationController
|
|||||||
|
|
||||||
socket.on :message do |event|
|
socket.on :message do |event|
|
||||||
Rails.logger.info( Time.now.getutc.to_s + ": Docker sending: " + event.data)
|
Rails.logger.info( Time.now.getutc.to_s + ": Docker sending: " + event.data)
|
||||||
handle_message(event.data, tubesock)
|
handle_message(event.data, tubesock, result[:container])
|
||||||
end
|
end
|
||||||
|
|
||||||
socket.on :close do |event|
|
socket.on :close do |event|
|
||||||
@ -171,10 +171,11 @@ class SubmissionsController < ApplicationController
|
|||||||
tubesock.close
|
tubesock.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_message(message, tubesock)
|
def handle_message(message, tubesock, container)
|
||||||
# Handle special commands first
|
# Handle special commands first
|
||||||
if (/^exit/.match(message))
|
if (/^exit/.match(message))
|
||||||
kill_socket(tubesock)
|
kill_socket(tubesock)
|
||||||
|
@docker_client.exit_container(container)
|
||||||
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])
|
||||||
|
@ -261,16 +261,21 @@ class DockerClient
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def exit_container(container)
|
def exit_thread_if_alive
|
||||||
Rails.logger.debug('exiting container ' + container.to_s)
|
|
||||||
# exit the timeout thread if it is still alive
|
|
||||||
if(@thread && @thread.alive?)
|
if(@thread && @thread.alive?)
|
||||||
@thread.exit
|
@thread.exit
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def exit_container(container)
|
||||||
|
Rails.logger.debug('exiting container ' + container.to_s)
|
||||||
|
# exit the timeout thread if it is still alive
|
||||||
|
exit_thread_if_alive
|
||||||
# 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
|
||||||
|
|
||||||
|
|
||||||
def kill_container(container)
|
def kill_container(container)
|
||||||
Rails.logger.info('killing container ' + container.to_s)
|
Rails.logger.info('killing container ' + container.to_s)
|
||||||
# remove container from pool, then destroy it
|
# remove container from pool, then destroy it
|
||||||
@ -286,6 +291,7 @@ class DockerClient
|
|||||||
container = self.class.create_container(@execution_environment)
|
container = self.class.create_container(@execution_environment)
|
||||||
DockerContainerPool.add_to_all_containers(container, @execution_environment)
|
DockerContainerPool.add_to_all_containers(container, @execution_environment)
|
||||||
end
|
end
|
||||||
|
exit_thread_if_alive
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_run_command(submission, filename, &block)
|
def execute_run_command(submission, filename, &block)
|
||||||
|
Reference in New Issue
Block a user