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
32 object.components.each do |cname, c|
35 pj = {index: i, name: cname}
36 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
38 pj[:percent_running] = 0
42 pj[:percent_done] = 100
47 if pj[:job][:tasks_summary]
49 ts = pj[:job][:tasks_summary]
50 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
51 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
52 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
53 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
54 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
57 pj[:percent_done] = 0.0
58 pj[:percent_running] = 100.0
65 pj[:result] = 'complete'
68 elsif pj[:job][:finished_at]
69 pj[:result] = 'failed'
71 elsif pj[:job][:started_at]
72 pj[:result] = 'running'
74 pj[:result] = 'queued'
78 pj[:job_id] = pj[:job][:uuid]
79 pj[:script] = pj[:job][:script] || c[:script]
80 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
81 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
82 pj[:output] = pj[:job][:output]
83 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
89 def pipeline_jobs_oldschool object
91 object.components[:steps].each_with_index do |step, i|
92 pj = {index: i, name: step[:name]}
93 if step[:complete] and step[:complete] != 0
94 if step[:output_data_locator]
100 if step[:progress] and
101 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
102 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
107 pj[:result] = 'failed'
111 if step[:warehousejob]
113 pj[:result] = 'complete'
116 elsif step[:warehousejob][:finishtime]
117 pj[:result] = 'failed'
119 elsif step[:warehousejob][:starttime]
120 pj[:result] = 'running'
122 pj[:result] = 'queued'
125 pj[:progress_detail] = (step[:progress] rescue nil)
126 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
127 pj[:job_link] = pj[:job_id]
128 pj[:script] = step[:function]
129 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
130 pj[:output] = step[:output_data_locator]
131 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)