From b269a738f57bf6a493ad1f0656b2efccddbde832 Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Tue, 1 Mar 2016 11:25:49 +0100 Subject: [PATCH] renamed execute_websocket_command to open_websocket_connection, because we now run the command after all listeners in the submissions controller were attached --- app/controllers/submissions_controller.rb | 5 +++++ lib/docker_client.rb | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 5bac07c4..1bc5cecf 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -139,6 +139,11 @@ class SubmissionsController < ApplicationController Rails.logger.debug('Rescued parsing error, sent the received client data to docker:' + data) end end + + # Send command after all listeners are attached. + # Newline required to flush + socket.send command + "\n" + Rails.logger.info('Sent command: ' + command.to_s) else kill_socket(tubesock) end diff --git a/lib/docker_client.rb b/lib/docker_client.rb index 3aaba69f..80986377 100644 --- a/lib/docker_client.rb +++ b/lib/docker_client.rb @@ -218,7 +218,7 @@ class DockerClient end #called when the user clicks the "Run" button - def execute_websocket_command(command, before_execution_block, output_consuming_block) + def open_websocket_connection(command, before_execution_block, output_consuming_block) @container = DockerContainerPool.get_container(@execution_environment) if @container @container.status = :executing @@ -231,10 +231,7 @@ class DockerClient end # TODO: catch exception if socket could not be created @socket ||= create_socket(@container) - # Newline required to flush - @socket.send command + "\n" - Rails.logger.info('Sent command: ' + command.to_s) - {status: :container_running, socket: @socket, container: @container} + {status: :container_running, socket: @socket, container: @container, command: command} else {status: :container_depleted} end @@ -297,7 +294,8 @@ class DockerClient """ command = submission.execution_environment.run_command % command_substitutions(filename) create_workspace_files = proc { create_workspace_files(container, submission) } - execute_websocket_command(command, create_workspace_files, block) + open_websocket_connection(command, create_workspace_files, block) + # actual run command is run in the submissions controller, after all listeners are attached. end def execute_test_command(submission, filename, &block)