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]
28 def pipeline_jobs_newschool object
34 template = PipelineTemplate.find(@object.pipeline_template_uuid) rescue nil
36 order = PipelineTemplatesHelper::sort_components(template.components)
38 if object.components[k]
39 comp.push([k, object.components[k]])
43 object.components.each do |k, v|
48 comp.each do |cname, c|
51 pj = {index: i, name: cname}
52 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
54 pj[:percent_running] = 0
58 pj[:percent_done] = 100
63 if pj[:job][:tasks_summary]
65 ts = pj[:job][:tasks_summary]
66 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
67 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
68 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
69 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
70 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
73 pj[:percent_done] = 0.0
74 pj[:percent_running] = 100.0
81 pj[:result] = 'complete'
84 elsif pj[:job][:finished_at]
85 pj[:result] = 'failed'
87 elsif pj[:job][:started_at]
88 pj[:result] = 'running'
90 pj[:result] = 'queued'
94 pj[:job_id] = pj[:job][:uuid]
95 pj[:script] = pj[:job][:script] || c[:script]
96 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
97 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
98 pj[:output] = pj[:job][:output]
99 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
105 def pipeline_jobs_oldschool object
107 object.components[:steps].each_with_index do |step, i|
108 pj = {index: i, name: step[:name]}
109 if step[:complete] and step[:complete] != 0
110 if step[:output_data_locator]
116 if step[:progress] and
117 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
118 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
123 pj[:result] = 'failed'
127 if step[:warehousejob]
129 pj[:result] = 'complete'
132 elsif step[:warehousejob][:finishtime]
133 pj[:result] = 'failed'
135 elsif step[:warehousejob][:starttime]
136 pj[:result] = 'running'
138 pj[:result] = 'queued'
141 pj[:progress_detail] = (step[:progress] rescue nil)
142 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
143 pj[:job_link] = pj[:job_id]
144 pj[:script] = step[:function]
145 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
146 pj[:output] = step[:output_data_locator]
147 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)