Editor: Allow file retrieval after code run
This commit is contained in:

committed by
Sebastian Serth

parent
fb9672c7a4
commit
60078701f5
@@ -18,6 +18,8 @@ module CodeOcean
|
||||
before_validation :set_ancestor_values, if: :incomplete_descendent?
|
||||
|
||||
attr_writer :size
|
||||
# These attributes are mainly used when retrieving files from a runner
|
||||
attr_accessor :download_path
|
||||
|
||||
belongs_to :context, polymorphic: true
|
||||
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
|
||||
@@ -100,6 +102,14 @@ module CodeOcean
|
||||
end
|
||||
end
|
||||
|
||||
def filepath_without_extension
|
||||
if path.present?
|
||||
::File.join(path, name)
|
||||
else
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
def hash_content
|
||||
self.hashed_content = Digest::MD5.new.hexdigest(read || '')
|
||||
end
|
||||
@@ -114,6 +124,10 @@ module CodeOcean
|
||||
name.to_s + (file_type&.file_extension || '')
|
||||
end
|
||||
|
||||
def name_with_extension_and_size
|
||||
"#{name_with_extension} (#{ActionController::Base.helpers.number_to_human_size(size)})"
|
||||
end
|
||||
|
||||
def set_ancestor_values
|
||||
%i[feedback_message file_type_id hidden name path read_only role weight].each do |attribute|
|
||||
send(:"#{attribute}=", ancestor.send(attribute))
|
||||
|
@@ -52,6 +52,34 @@ class Runner < ApplicationRecord
|
||||
@strategy.copy_files(files)
|
||||
end
|
||||
|
||||
def download_file(path, **options, &block)
|
||||
@strategy.download_file(path, **options, &block)
|
||||
end
|
||||
|
||||
def retrieve_files(raise_exception: true, **options)
|
||||
try = 0
|
||||
begin
|
||||
if try.nonzero?
|
||||
request_new_id
|
||||
save
|
||||
end
|
||||
@strategy.retrieve_files(**options)
|
||||
rescue Runner::Error::RunnerNotFound => e
|
||||
Rails.logger.debug { "Retrieving files failed for the first time: #{e.message}" }
|
||||
try += 1
|
||||
|
||||
if try == 1
|
||||
# This is only used if no files were copied to the runner. Thus requesting a second runner is performed here
|
||||
# Reset the variable. This is required to prevent raising an outdated exception after a successful second try
|
||||
e = nil
|
||||
retry
|
||||
end
|
||||
ensure
|
||||
# We forward the exception if requested
|
||||
raise e if raise_exception && defined?(e) && e.present?
|
||||
end
|
||||
end
|
||||
|
||||
def attach_to_execution(command, privileged_execution: false, &block)
|
||||
Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Starting execution with Runner #{id} for #{user_type} #{user_id}." }
|
||||
starting_time = Time.zone.now
|
||||
|
@@ -17,6 +17,7 @@ class TestrunMessage < ApplicationRecord
|
||||
exception: 10,
|
||||
result: 11,
|
||||
canvasevent: 12,
|
||||
files: 13,
|
||||
}, _default: :write, _prefix: true
|
||||
|
||||
enum stream: {
|
||||
|
Reference in New Issue
Block a user