Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions BrainPortal/lib/boutiques_output_filename_renamer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,53 @@ def after_form
message
end



# checking that output patterns actually provided in the case of batch tasks
# because this module disables CBRAIN standards output suffixes that aim at aprevenitn
# from overwriting the output files
def final_task_list
tasklist = super
if tasklist.length > 1 && tasklist.last.is_a?(CbrainTask)
descriptor = descriptor_for_final_task_list
config_map = descriptor.custom_module_info('BoutiquesOutputFilenameRenamer') || {}

# check that the output file names are unique at least for same output id
# (still there could be overwriting for different output ids)

config_map.each do |_, pair|
fileinputid, outnameinputid = *pair
original_outname_pattern = invoke_params[outnameinputid]
next if original_outname_pattern.include?('{task_id}') # usually enough for unique output names for input
outname_pattern = original_outname_pattern.gsub('{time}', '12:23:45') # time is not very reliable
outnames = {}
outname = input_userfile = nil
t, _ = tasklist.each_with_index.detect do |t, i|
input_userfile_id = t.invoke_params[fileinputid]
input_userfile = Userfile.find(input_userfile_id)
outname = t.output_name_from_pattern(outname_pattern, input_userfile.name) # expected output file name
outnames[outname] ||= i # index of the first task in the tasklist, resulting in output file name 'outname'
outnames[outname] < i # the file name could be generate both by i-th and one of previous tasks
end

if !t.nil?
t_1 = tasklist[outnames[outname]]
input_userfile_id_1 = t_1.invoke_params[fileinputid] # input file id resulting in duplicated output file name
input_userfile_1 = Userfile.find(input_userfile_id_1)

msg = ":BoutiquesOutputFilenameRenamer module require unique output names for batch tasks," +
"yet input files '#{input_userfile.name}' and '#{input_userfile_1.name}' result in the same output file " +
" '#{outname}' for output file pattern '#{original_outname_pattern}'."

self.errors.add(outnameinputid, ": Add a pattern that may result in different files names, such a {full} or {task} to '#{outname_pattern}' ")
t.errors.add(outnameinputid, msg)
end
end
end
tasklist
end


##################################################
# Cluster side overrides
##################################################
Expand Down
Loading