Debugging

This commit is contained in:
Jan Renz
2015-04-23 12:58:21 +02:00
parent 40f37410ac
commit a5d5dde7a8
2 changed files with 32 additions and 23 deletions

View File

@ -72,15 +72,23 @@ class SubmissionsController < ApplicationController
with_server_sent_events do |server_sent_event|
container_info_sent = false
stderr = ''
output = @docker_client.execute_run_command(@submission, params[:filename]) 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
output = @docker_client.execute_run_command(@submission, params[:filename])
if output
server_sent_event.write({stdout: output[:stdout]}, event: 'output')
server_sent_event.write({stderr: output[:stderr]}, event: 'output')
output[:status] = :ok if output[:status] == 0
server_sent_event.write({status: output[:status]}, event: 'status')
end
server_sent_event.write({stream => chunk}, event: 'output')
stderr += chunk if stream == :stderr
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 hint = Whistleblower.new(execution_environment: @submission.execution_environment).generate_hint(stderr)
server_sent_event.write(hint, event: 'hint')

View File

@ -176,34 +176,35 @@ class DockerClient
def send_command(command, container, &block)
Timeout.timeout(@execution_environment.permitted_execution_time.to_i) do
stderr = []
stdout = []
container.exec(['bash', '-c', command]) do |stream, chunk|
block.call(stream, chunk) if block_given?
if stream == :stderr
stderr.push(chunk)
else
stdout.push(chunk)
end
end
{status: :ok, stderr: stderr.join, stdout: stdout.join}
output = container.exec(['bash', '-c', command])
#do |stream, chunk|
# block.call(stream, chunk) if block_given? #this may issue
# if stream == :stderr
## stderr.push(chunk)
# else
# stdout.push(chunk)
# end
#end
Rails.logger.info output
{status: output[2], stderr: output[1].join, stdout: output[0].join}
end
rescue Timeout::Error
timeout_occured = true
Rails.logger.info('got timeout error for container ' + container.to_s)
#container.restart if RECYCLE_CONTAINERS
DockerContainerPool.remove_from_all_containers(container, @execution_environment)
# destroy container
destroy_container(container)
self.class.destroy_container(container)
if(RECYCLE_CONTAINERS)
# 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)
end
{status: :timeout}
{status: :timeout, stderr: '', stdout: ''}
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)
end
private :send_command