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 pipeline_log_history(job_uuids)
28 log_history = Log.where(event_type: 'stderr',
29 object_uuid: job_uuids).order('id DESC')
30 if !log_history.results.empty?
31 reversed_results = log_history.results.reverse
32 reversed_results.each do |entry|
33 if entry.andand.properties
34 properties = entry.properties
35 text = properties[:text]
37 results = results.concat text.split("\n")
48 def pipeline_jobs_newschool object
52 object.components.each do |cname, c|
54 pj = {index: i, name: cname}
59 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
61 pj[:percent_running] = 0
65 pj[:percent_done] = 100
70 if pj[:job][:tasks_summary]
72 ts = pj[:job][:tasks_summary]
73 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
74 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
75 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
76 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
77 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
80 pj[:percent_done] = 0.0
81 pj[:percent_running] = 100.0
88 pj[:result] = 'complete'
89 pj[:labeltype] = 'success'
92 elsif pj[:job][:finished_at]
93 pj[:result] = 'failed'
94 pj[:labeltype] = 'danger'
96 elsif pj[:job][:started_at]
97 pj[:result] = 'running'
98 pj[:labeltype] = 'primary'
100 pj[:result] = 'queued'
101 pj[:labeltype] = 'default'
104 pj[:labeltype] = 'default'
106 pj[:job_id] = pj[:job][:uuid]
107 pj[:script] = pj[:job][:script] || c[:script]
108 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
109 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
110 pj[:output] = pj[:job][:output]
111 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
117 def pipeline_jobs_oldschool object
119 object.components[:steps].each_with_index do |step, i|
120 pj = {index: i, name: step[:name]}
121 if step[:complete] and step[:complete] != 0
122 if step[:output_data_locator]
128 if step[:progress] and
129 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
130 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
135 pj[:result] = 'failed'
139 if step[:warehousejob]
141 pj[:result] = 'complete'
144 elsif step[:warehousejob][:finishtime]
145 pj[:result] = 'failed'
147 elsif step[:warehousejob][:starttime]
148 pj[:result] = 'running'
150 pj[:result] = 'queued'
153 pj[:progress_detail] = (step[:progress] rescue nil)
154 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
155 pj[:job_link] = pj[:job_id]
156 pj[:script] = step[:function]
157 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
158 pj[:output] = step[:output_data_locator]
159 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)