1 module PipelineInstancesHelper
3 def pipeline_jobs object=nil
5 if object.components[:steps].is_a? Array
6 pipeline_jobs_oldschool object
7 elsif object.components.is_a? Hash
8 pipeline_jobs_newschool object
12 def render_pipeline_jobs
13 pipeline_jobs.collect do |pj|
14 render_pipeline_job pj
18 def render_pipeline_job pj
19 pj[:progress_bar] = render partial: 'job_progress', locals: {:j => pj[:job]}
20 pj[:output_link] = link_to_if_arvados_object pj[:output]
21 pj[:job_link] = link_to_if_arvados_object pj[:job][:uuid]
25 def pipieline_log_history(job_uuids)
28 log_history = Log.where(event_type: 'transient-log-entry',
29 object_uuid: job_uuids).order('id DESC').limit(5).all
30 if !log_history.results.empty?
31 results = log_history.results.reverse
39 def pipeline_jobs_newschool object
43 object.components.each do |cname, c|
45 pj = {index: i, name: cname}
46 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
48 pj[:percent_running] = 0
52 pj[:percent_done] = 100
57 if pj[:job][:tasks_summary]
59 ts = pj[:job][:tasks_summary]
60 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
61 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
62 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
63 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
64 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
67 pj[:percent_done] = 0.0
68 pj[:percent_running] = 100.0
75 pj[:result] = 'complete'
78 elsif pj[:job][:finished_at]
79 pj[:result] = 'failed'
81 elsif pj[:job][:started_at]
82 pj[:result] = 'running'
84 pj[:result] = 'queued'
88 pj[:job_id] = pj[:job][:uuid]
89 pj[:script] = pj[:job][:script] || c[:script]
90 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
91 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
92 pj[:output] = pj[:job][:output]
93 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
99 def pipeline_jobs_oldschool object
101 object.components[:steps].each_with_index do |step, i|
102 pj = {index: i, name: step[:name]}
103 if step[:complete] and step[:complete] != 0
104 if step[:output_data_locator]
110 if step[:progress] and
111 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
112 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
117 pj[:result] = 'failed'
121 if step[:warehousejob]
123 pj[:result] = 'complete'
126 elsif step[:warehousejob][:finishtime]
127 pj[:result] = 'failed'
129 elsif step[:warehousejob][:starttime]
130 pj[:result] = 'running'
132 pj[:result] = 'queued'
135 pj[:progress_detail] = (step[:progress] rescue nil)
136 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
137 pj[:job_link] = pj[:job_id]
138 pj[:script] = step[:function]
139 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
140 pj[:output] = step[:output_data_locator]
141 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)