Debugging
This commit is contained in:
@ -72,15 +72,23 @@ class SubmissionsController < ApplicationController
|
|||||||
with_server_sent_events do |server_sent_event|
|
with_server_sent_events do |server_sent_event|
|
||||||
container_info_sent = false
|
container_info_sent = false
|
||||||
stderr = ''
|
stderr = ''
|
||||||
output = @docker_client.execute_run_command(@submission, params[:filename]) do |stream, chunk|
|
output = @docker_client.execute_run_command(@submission, params[:filename])
|
||||||
unless container_info_sent
|
if output
|
||||||
server_sent_event.write({id: @docker_client.container.try(:id), port_bindings: @docker_client.container.try(:port_bindings)}, event: 'info')
|
server_sent_event.write({stdout: output[:stdout]}, event: 'output')
|
||||||
container_info_sent = true
|
server_sent_event.write({stderr: output[:stderr]}, event: 'output')
|
||||||
end
|
output[:status] = :ok if output[:status] == 0
|
||||||
server_sent_event.write({stream => chunk}, event: 'output')
|
server_sent_event.write({status: output[:status]}, event: 'status')
|
||||||
stderr += chunk if stream == :stderr
|
|
||||||
end
|
end
|
||||||
server_sent_event.write(output, event: 'status')
|
#server_sent_event.write({stdout: output[:output][2], event: 'status')
|
||||||
|
# do |stream, chunk|
|
||||||
|
# unless container_info_sent
|
||||||
|
# server_sent_event.write({id: @docker_client.container.try(:id), port_bindings: @docker_client.container.try(:port_bindings)}, event: 'info')
|
||||||
|
# container_info_sent = true
|
||||||
|
# end
|
||||||
|
# server_sent_event.write({stream => chunk}, event: 'output')
|
||||||
|
# stderr += chunk if stream == :stderr
|
||||||
|
# end
|
||||||
|
# server_sent_event.write(output, event: 'status')
|
||||||
if stderr.present?
|
if stderr.present?
|
||||||
if hint = Whistleblower.new(execution_environment: @submission.execution_environment).generate_hint(stderr)
|
if hint = Whistleblower.new(execution_environment: @submission.execution_environment).generate_hint(stderr)
|
||||||
server_sent_event.write(hint, event: 'hint')
|
server_sent_event.write(hint, event: 'hint')
|
||||||
|
@ -176,34 +176,35 @@ class DockerClient
|
|||||||
|
|
||||||
def send_command(command, container, &block)
|
def send_command(command, container, &block)
|
||||||
Timeout.timeout(@execution_environment.permitted_execution_time.to_i) do
|
Timeout.timeout(@execution_environment.permitted_execution_time.to_i) do
|
||||||
stderr = []
|
output = container.exec(['bash', '-c', command])
|
||||||
stdout = []
|
#do |stream, chunk|
|
||||||
container.exec(['bash', '-c', command]) do |stream, chunk|
|
# block.call(stream, chunk) if block_given? #this may issue
|
||||||
block.call(stream, chunk) if block_given?
|
# if stream == :stderr
|
||||||
if stream == :stderr
|
## stderr.push(chunk)
|
||||||
stderr.push(chunk)
|
# else
|
||||||
else
|
# stdout.push(chunk)
|
||||||
stdout.push(chunk)
|
# end
|
||||||
end
|
#end
|
||||||
end
|
Rails.logger.info output
|
||||||
{status: :ok, stderr: stderr.join, stdout: stdout.join}
|
{status: output[2], stderr: output[1].join, stdout: output[0].join}
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
timeout_occured = true
|
||||||
Rails.logger.info('got timeout error for container ' + container.to_s)
|
Rails.logger.info('got timeout error for container ' + container.to_s)
|
||||||
#container.restart if RECYCLE_CONTAINERS
|
#container.restart if RECYCLE_CONTAINERS
|
||||||
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
|
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
|
||||||
|
|
||||||
# destroy container
|
# destroy container
|
||||||
destroy_container(container)
|
self.class.destroy_container(container)
|
||||||
|
|
||||||
if(RECYCLE_CONTAINERS)
|
if(RECYCLE_CONTAINERS)
|
||||||
# create new container and add it to @all_containers. will be added to @containers on return_container
|
# create new container and add it to @all_containers. will be added to @containers on return_container
|
||||||
container = 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
|
||||||
{status: :timeout}
|
{status: :timeout, stderr: '', stdout: ''}
|
||||||
ensure
|
ensure
|
||||||
Rails.logger.info('after timeout error ensuring for' + container.to_s)
|
Rails.logger.info('send_command ensuring for' + container.to_s)
|
||||||
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
|
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
|
||||||
end
|
end
|
||||||
private :send_command
|
private :send_command
|
||||||
|
Reference in New Issue
Block a user