Fix code style to reduce errors in RubyMine
This commit is contained in:
@ -43,6 +43,7 @@ class DockerClient
|
|||||||
module_name: File.basename(filename, File.extname(filename)).underscore
|
module_name: File.basename(filename, File.extname(filename)).underscore
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
private :command_substitutions
|
private :command_substitutions
|
||||||
|
|
||||||
def self.config
|
def self.config
|
||||||
@ -73,7 +74,7 @@ class DockerClient
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_socket(container, stderr=false)
|
def create_socket(container, stderr = false)
|
||||||
# todo factor out query params
|
# todo factor out query params
|
||||||
# todo separate stderr
|
# todo separate stderr
|
||||||
query_params = 'logs=0&stream=1&' + (stderr ? 'stderr=1' : 'stdout=1&stdin=1')
|
query_params = 'logs=0&stream=1&' + (stderr ? 'stderr=1' : 'stdout=1&stdin=1')
|
||||||
@ -136,6 +137,7 @@ class DockerClient
|
|||||||
rescue Docker::Error::NotFoundError => error
|
rescue Docker::Error::NotFoundError => error
|
||||||
Rails.logger.info('create_workspace_files: Rescued from Docker::Error::NotFoundError: ' + error.to_s)
|
Rails.logger.info('create_workspace_files: Rescued from Docker::Error::NotFoundError: ' + error.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
private :create_workspace_files
|
private :create_workspace_files
|
||||||
|
|
||||||
def create_workspace_file(options = {})
|
def create_workspace_file(options = {})
|
||||||
@ -144,12 +146,13 @@ class DockerClient
|
|||||||
file.write(options[:file].content)
|
file.write(options[:file].content)
|
||||||
file.close
|
file.close
|
||||||
end
|
end
|
||||||
|
|
||||||
private :create_workspace_file
|
private :create_workspace_file
|
||||||
|
|
||||||
def create_workspace_files_transmit(container, submission)
|
def create_workspace_files_transmit(container, submission)
|
||||||
begin
|
begin
|
||||||
# create a temporary dir, put all files in it, and put it into the container. the dir is automatically removed when leaving the block.
|
# create a temporary dir, put all files in it, and put it into the container. the dir is automatically removed when leaving the block.
|
||||||
Dir.mktmpdir {|dir|
|
Dir.mktmpdir { |dir|
|
||||||
submission.collect_files.each do |file|
|
submission.collect_files.each do |file|
|
||||||
disk_file = File.new(dir + '/' + (file.path || '') + file.name_with_extension, 'w')
|
disk_file = File.new(dir + '/' + (file.path || '') + file.name_with_extension, 'w')
|
||||||
disk_file.write(file.content)
|
disk_file.write(file.content)
|
||||||
@ -258,10 +261,10 @@ class DockerClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def kill_after_timeout(container)
|
def kill_after_timeout(container)
|
||||||
"""
|
"" "
|
||||||
We need to start a second thread to kill the websocket connection,
|
We need to start a second thread to kill the websocket connection,
|
||||||
as it is impossible to determine whether further input is requested.
|
as it is impossible to determine whether further input is requested.
|
||||||
"""
|
" ""
|
||||||
@thread = Thread.new do
|
@thread = Thread.new do
|
||||||
#begin
|
#begin
|
||||||
timeout = @execution_environment.permitted_execution_time.to_i # seconds
|
timeout = @execution_environment.permitted_execution_time.to_i # seconds
|
||||||
@ -269,10 +272,10 @@ class DockerClient
|
|||||||
if container.status != :returned
|
if container.status != :returned
|
||||||
Rails.logger.info('Killing container after timeout of ' + timeout.to_s + ' seconds.')
|
Rails.logger.info('Killing container after timeout of ' + timeout.to_s + ' seconds.')
|
||||||
# send timeout to the tubesock socket
|
# send timeout to the tubesock socket
|
||||||
if(@tubesock)
|
if (@tubesock)
|
||||||
@tubesock.send_data JSON.dump({'cmd' => 'timeout'})
|
@tubesock.send_data JSON.dump({'cmd' => 'timeout'})
|
||||||
end
|
end
|
||||||
if(@socket)
|
if (@socket)
|
||||||
@socket.send('#timeout')
|
@socket.send('#timeout')
|
||||||
#sleep one more second to ensure that the message reaches the submissions_controller.
|
#sleep one more second to ensure that the message reaches the submissions_controller.
|
||||||
sleep(1)
|
sleep(1)
|
||||||
@ -290,7 +293,7 @@ class DockerClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def exit_thread_if_alive
|
def exit_thread_if_alive
|
||||||
if(@thread && @thread.alive?)
|
if (@thread && @thread.alive?)
|
||||||
@thread.exit
|
@thread.exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -324,10 +327,10 @@ class DockerClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute_run_command(submission, filename, &block)
|
def execute_run_command(submission, filename, &block)
|
||||||
"""
|
"" "
|
||||||
Run commands by attaching a websocket to Docker.
|
Run commands by attaching a websocket to Docker.
|
||||||
"""
|
" ""
|
||||||
filepath = submission.collect_files.find{|f| f.name_with_extension == filename}.filepath
|
filepath = submission.collect_files.find { |f| f.name_with_extension == filename }.filepath
|
||||||
command = submission.execution_environment.run_command % command_substitutions(filepath)
|
command = submission.execution_environment.run_command % command_substitutions(filepath)
|
||||||
create_workspace_files = proc { create_workspace_files(container, submission) }
|
create_workspace_files = proc { create_workspace_files(container, submission) }
|
||||||
open_websocket_connection(command, create_workspace_files, block)
|
open_websocket_connection(command, create_workspace_files, block)
|
||||||
@ -335,10 +338,10 @@ class DockerClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute_test_command(submission, filename, &block)
|
def execute_test_command(submission, filename, &block)
|
||||||
"""
|
"" "
|
||||||
Stick to existing Docker API with exec command.
|
Stick to existing Docker API with exec command.
|
||||||
"""
|
" ""
|
||||||
filepath = submission.collect_files.find{|f| f.name_with_extension == filename}.filepath
|
filepath = submission.collect_files.find { |f| f.name_with_extension == filename }.filepath
|
||||||
command = submission.execution_environment.test_command % command_substitutions(filepath)
|
command = submission.execution_environment.test_command % command_substitutions(filepath)
|
||||||
create_workspace_files = proc { create_workspace_files(container, submission) }
|
create_workspace_files = proc { create_workspace_files(container, submission) }
|
||||||
execute_command(command, create_workspace_files, block)
|
execute_command(command, create_workspace_files, block)
|
||||||
@ -386,6 +389,7 @@ class DockerClient
|
|||||||
def local_file_path(options = {})
|
def local_file_path(options = {})
|
||||||
File.join(self.class.local_workspace_path(options[:container]), options[:file].path || '', options[:file].name_with_extension)
|
File.join(self.class.local_workspace_path(options[:container]), options[:file].path || '', options[:file].name_with_extension)
|
||||||
end
|
end
|
||||||
|
|
||||||
private :local_file_path
|
private :local_file_path
|
||||||
|
|
||||||
def self.local_workspace_path(container)
|
def self.local_workspace_path(container)
|
||||||
@ -420,6 +424,7 @@ class DockerClient
|
|||||||
DockerContainerPool.return_container(container, execution_environment)
|
DockerContainerPool.return_container(container, execution_environment)
|
||||||
container.status = :returned
|
container.status = :returned
|
||||||
end
|
end
|
||||||
|
|
||||||
#private :return_container
|
#private :return_container
|
||||||
|
|
||||||
def send_command(command, container, &block)
|
def send_command(command, container, &block)
|
||||||
@ -445,7 +450,9 @@ class DockerClient
|
|||||||
kill_container(container)
|
kill_container(container)
|
||||||
{status: :timeout}
|
{status: :timeout}
|
||||||
end
|
end
|
||||||
|
|
||||||
private :send_command
|
private :send_command
|
||||||
|
|
||||||
class Error < RuntimeError; end
|
class Error < RuntimeError;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user