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}
55 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
57 pj[:percent_running] = 0
61 pj[:percent_done] = 100
66 if pj[:job][:tasks_summary]
68 ts = pj[:job][:tasks_summary]
69 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
70 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
71 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
72 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
73 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
76 pj[:percent_done] = 0.0
77 pj[:percent_running] = 100.0
84 pj[:result] = 'complete'
85 pj[:labeltype] = 'success'
88 elsif pj[:job][:finished_at]
89 pj[:result] = 'failed'
90 pj[:labeltype] = 'danger'
92 elsif pj[:job][:started_at]
93 pj[:result] = 'running'
94 pj[:labeltype] = 'primary'
96 pj[:result] = 'queued'
97 pj[:labeltype] = 'default'
100 pj[:labeltype] = 'default'
102 pj[:job_id] = pj[:job][:uuid]
103 pj[:script] = pj[:job][:script] || c[:script]
104 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
105 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
106 pj[:output] = pj[:job][:output]
107 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
113 def pipeline_jobs_oldschool object
115 object.components[:steps].each_with_index do |step, i|
116 pj = {index: i, name: step[:name]}
117 if step[:complete] and step[:complete] != 0
118 if step[:output_data_locator]
124 if step[:progress] and
125 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
126 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
131 pj[:result] = 'failed'
135 if step[:warehousejob]
137 pj[:result] = 'complete'
140 elsif step[:warehousejob][:finishtime]
141 pj[:result] = 'failed'
143 elsif step[:warehousejob][:starttime]
144 pj[:result] = 'running'
146 pj[:result] = 'queued'
149 pj[:progress_detail] = (step[:progress] rescue nil)
150 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
151 pj[:job_link] = pj[:job_id]
152 pj[:script] = step[:function]
153 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
154 pj[:output] = step[:output_data_locator]
155 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)