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|
34 pj = {index: i, name: cname}
35 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
37 pj[:percent_running] = 0
41 pj[:percent_done] = 100
46 if pj[:job][:tasks_summary]
48 ts = pj[:job][:tasks_summary]
49 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
50 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
51 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
52 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
53 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
56 pj[:percent_done] = 0.0
57 pj[:percent_running] = 100.0
64 pj[:result] = 'complete'
67 elsif pj[:job][:finished_at]
68 pj[:result] = 'failed'
70 elsif pj[:job][:started_at]
71 pj[:result] = 'running'
73 pj[:result] = 'queued'
77 pj[:job_id] = pj[:job][:uuid]
78 pj[:script] = pj[:job][:script] || c[:script]
79 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
80 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
81 pj[:output] = pj[:job][:output]
82 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
88 def pipeline_jobs_oldschool object
90 object.components[:steps].each_with_index do |step, i|
91 pj = {index: i, name: step[:name]}
92 if step[:complete] and step[:complete] != 0
93 if step[:output_data_locator]
99 if step[:progress] and
100 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
101 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
106 pj[:result] = 'failed'
110 if step[:warehousejob]
112 pj[:result] = 'complete'
115 elsif step[:warehousejob][:finishtime]
116 pj[:result] = 'failed'
118 elsif step[:warehousejob][:starttime]
119 pj[:result] = 'running'
121 pj[:result] = 'queued'
124 pj[:progress_detail] = (step[:progress] rescue nil)
125 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
126 pj[:job_link] = pj[:job_id]
127 pj[:script] = step[:function]
128 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
129 pj[:output] = step[:output_data_locator]
130 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)