X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7df2da959b583d3646b9fde606f9e74d598d4bb9..9be9761666fd091496bee885b37598db9a6ab38a:/apps/workbench/app/helpers/pipeline_instances_helper.rb diff --git a/apps/workbench/app/helpers/pipeline_instances_helper.rb b/apps/workbench/app/helpers/pipeline_instances_helper.rb index 35d28d542b..995b1c3e64 100644 --- a/apps/workbench/app/helpers/pipeline_instances_helper.rb +++ b/apps/workbench/app/helpers/pipeline_instances_helper.rb @@ -22,25 +22,54 @@ module PipelineInstancesHelper pj end - def pipeline_log_history(job_uuids) - results = [] - - log_history = Log.where(event_type: 'stderr', - object_uuid: job_uuids).order('id DESC') - if !log_history.results.empty? - reversed_results = log_history.results.reverse - reversed_results.each do |entry| - if entry.andand.properties - properties = entry.properties - text = properties[:text] - if text - results = results.concat text.split("\n") - end + def merge_range timestamps, started_at, finished_at + timestamps.each_index do |i| + if started_at + if started_at >= timestamps[i][0] and finished_at <= timestamps[i][1] + # 'j' started and ended during 'i' + return timestamps + end + + if started_at < timestamps[i][0] and finished_at >= timestamps[i][0] and finished_at <= timestamps[i][1] + # 'j' started before 'i' and finished during 'i' + # re-merge range between when 'j' started and 'i' finished + finished_at = timestamps[i][1] + timestamps.delete_at i + return merge_range timestamps, started_at, finished_at + end + + if started_at >= timestamps[i][0] and started_at <= timestamps[i][1] + # 'j' started during 'i' and finished sometime after + # move end time of 'i' back + # re-merge range between when 'i' started and 'j' finished + started_at = timestamps[i][0] + timestamps.delete_at i + return merge_range timestamps, started_at, finished_at + end + + if finished_at < timestamps[i][0] + # 'j' finished before 'i' started, so insert before 'i' + timestamps.insert i, [started_at, finished_at] + return timestamps end end end - return results + timestamps << [started_at, finished_at] + end + + def determine_wallclock_runtime jobs + puts "Begin #{jobs}" + timestamps = [] + jobs.each do |j| + insert_at = 0 + started_at = j[:started_at] + finished_at = (if j[:finished_at] then j[:finished_at] else Time.now end) + if started_at + timestamps = merge_range timestamps, started_at, finished_at + end + end + timestamps.map { |t| t[1] - t[0] }.reduce(:+) || 0 end protected @@ -49,10 +78,26 @@ module PipelineInstancesHelper ret = [] i = -1 + jobuuids = object.components.values.map { |c| + c[:job][:uuid] if c.is_a?(Hash) and c[:job].is_a?(Hash) + }.compact + job = {} + Job.where(uuid: jobuuids).each do |j| + job[j[:uuid]] = j + end + object.components.each do |cname, c| i += 1 pj = {index: i, name: cname} - pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {} + if not c.is_a?(Hash) + ret << pj + next + end + if c[:job] and c[:job][:uuid] and job[c[:job][:uuid]] + pj[:job] = job[c[:job][:uuid]] + else + pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {} + end pj[:percent_done] = 0 pj[:percent_running] = 0 if pj[:job][:success] @@ -99,11 +144,15 @@ module PipelineInstancesHelper pj[:result] = 'none' pj[:labeltype] = 'default' end + pj[:job_id] = pj[:job][:uuid] pj[:script] = pj[:job][:script] || c[:script] + pj[:repository] = pj[:job][:script] || c[:repository] pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters] pj[:script_version] = pj[:job][:script_version] || c[:script_version] + pj[:nondeterministic] = pj[:job][:nondeterministic] || c[:nondeterministic] pj[:output] = pj[:job][:output] + pj[:output_uuid] = c[:output_uuid] pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil) ret << pj end @@ -157,4 +206,34 @@ module PipelineInstancesHelper end ret end + + def runtime duration, long + hours = 0 + minutes = 0 + seconds = 0 + if duration >= 3600 + hours = (duration / 3600).floor + duration -= hours * 3600 + end + if duration >= 60 + minutes = (duration / 60).floor + duration -= minutes * 60 + end + duration = duration.floor + + if long + s = "" + if hours > 0 then + s += "#{hours} hour#{'s' if hours != 1} " + end + if minutes > 0 then + s += "#{minutes} minute#{'s' if minutes != 1} " + end + s += "#{duration} second#{'s' if duration != 1}" + else + s = "#{hours}:#{minutes.to_s.rjust(2, '0')}:#{duration.to_s.rjust(2, '0')}" + end + s + end + end