Merge pull request #17 from franzliedke/patch-1

Clean up after debugging session
This commit is contained in:
jprberlin
2015-04-23 13:17:29 +02:00
2 changed files with 11 additions and 30 deletions

View File

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

View File

@ -177,16 +177,9 @@ 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
output = container.exec(['bash', '-c', command]) output = container.exec(['bash', '-c', command])
#do |stream, chunk| Rails.logger.info "output from container.exec"
# 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 Rails.logger.info output
{status: output[2], stderr: output[1].join, stdout: output[0].join} {status: output[2] == 0 ? :ok : :failed, stdout: output[0].join, stderr: output[1].join}
end end
rescue Timeout::Error rescue Timeout::Error
timeout_occured = true timeout_occured = true
@ -202,7 +195,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
{status: :timeout, stderr: '', stdout: ''} {status: :timeout}
ensure ensure
Rails.logger.info('send_command 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)