From 95c461a0554a4975c6be031384550382dd56845a Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Sun, 8 Nov 2015 12:37:11 +0100 Subject: [PATCH] Hide parametrized run and test commands. Some logging changes, comment on possible thread code to release database connections, not sure whether necessary. --- app/controllers/submissions_controller.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index fb7ab0e2..3aa3adf4 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -25,6 +25,11 @@ class SubmissionsController < ApplicationController create_and_respond(object: @submission) end + def command_substitutions(filename) + {class_name: File.basename(filename, File.extname(filename)).camelize, filename: filename, module_name: File.basename(filename, File.extname(filename)).underscore} + end + private :command_substitutions + def copy_comments # copy each annotation and set the target_file.id unless(params[:annotations_arr].nil?) @@ -88,6 +93,11 @@ class SubmissionsController < ApplicationController # end hijack do |tubesock| + # probably add: + # ensure + # #guarantee that the thread is releasing the DB connection after it is done + # ActiveRecord::Base.connectionpool.releaseconnection + # end Thread.new { EventMachine.run } unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive? @@ -122,11 +132,11 @@ class SubmissionsController < ApplicationController @docker_client.exit_container(result[:container]) else socket.send data - Rails.logger.info('Sent the received data to docker:' + data) + Rails.logger.debug('Sent the received client data to docker:' + data) end rescue JSON::ParserError socket.send data - Rails.logger.info('Sent the received data to docker:' + data) + Rails.logger.debug('Rescued parsing error, sent the received client data to docker:' + data) end end else @@ -147,8 +157,8 @@ class SubmissionsController < ApplicationController kill_socket(tubesock) else # Filter out information about run_command, test_command, user or working directory - run_command = @submission.execution_environment.run_command - test_command = @submission.execution_environment.test_command + run_command = @submission.execution_environment.run_command % command_substitutions(params[:filename]) + test_command = @submission.execution_environment.test_command % command_substitutions(params[:filename]) if !(/root|workspace|#{run_command}|#{test_command}/.match(message)) parse_message(message, 'stdout', tubesock) end