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]
27 def pipeline_jobs_newschool object
31 jobuuids = object.components.values.map { |c|
32 c[:job][:uuid] if c.is_a?(Hash) and c[:job].is_a?(Hash)
35 Job.where(uuid: jobuuids).each do |j|
39 object.components.each do |cname, c|
41 pj = {index: i, name: cname}
46 if c[:job] and c[:job][:uuid] and job[c[:job][:uuid]]
47 pj[:job] = job[c[:job][:uuid]]
49 pj[:job] = c[:job].is_a?(Hash) ? c[:job] : {}
52 pj[:percent_running] = 0
56 pj[:percent_done] = 100
61 if pj[:job][:tasks_summary]
63 ts = pj[:job][:tasks_summary]
64 denom = ts[:done].to_f + ts[:running].to_f + ts[:todo].to_f
65 pj[:progress] = (ts[:done].to_f + ts[:running].to_f/2) / denom
66 pj[:percent_done] = 100.0 * ts[:done].to_f / denom
67 pj[:percent_running] = 100.0 * ts[:running].to_f / denom
68 pj[:progress_detail] = "#{ts[:done]} done #{ts[:running]} run #{ts[:todo]} todo"
71 pj[:percent_done] = 0.0
72 pj[:percent_running] = 100.0
79 pj[:result] = 'complete'
80 pj[:labeltype] = 'success'
83 elsif pj[:job][:finished_at]
84 pj[:result] = 'failed'
85 pj[:labeltype] = 'danger'
87 elsif pj[:job][:started_at]
88 pj[:result] = 'running'
89 pj[:labeltype] = 'primary'
91 pj[:result] = 'queued'
92 pj[:labeltype] = 'default'
95 pj[:labeltype] = 'default'
97 pj[:job_id] = pj[:job][:uuid]
98 pj[:script] = pj[:job][:script] || c[:script]
99 pj[:script_parameters] = pj[:job][:script_parameters] || c[:script_parameters]
100 pj[:script_version] = pj[:job][:script_version] || c[:script_version]
101 pj[:output] = pj[:job][:output]
102 pj[:output_uuid] = c[:output_uuid]
103 pj[:finished_at] = (Time.parse(pj[:job][:finished_at]) rescue nil)
109 def pipeline_jobs_oldschool object
111 object.components[:steps].each_with_index do |step, i|
112 pj = {index: i, name: step[:name]}
113 if step[:complete] and step[:complete] != 0
114 if step[:output_data_locator]
120 if step[:progress] and
121 (re = step[:progress].match /^(\d+)\+(\d+)\/(\d+)$/)
122 pj[:progress] = (((re[1].to_f + re[2].to_f/2) / re[3].to_f) rescue 0.5)
127 pj[:result] = 'failed'
131 if step[:warehousejob]
133 pj[:result] = 'complete'
136 elsif step[:warehousejob][:finishtime]
137 pj[:result] = 'failed'
139 elsif step[:warehousejob][:starttime]
140 pj[:result] = 'running'
142 pj[:result] = 'queued'
145 pj[:progress_detail] = (step[:progress] rescue nil)
146 pj[:job_id] = (step[:warehousejob][:id] rescue nil)
147 pj[:job_link] = pj[:job_id]
148 pj[:script] = step[:function]
149 pj[:script_version] = (step[:warehousejob][:revision] rescue nil)
150 pj[:output] = step[:output_data_locator]
151 pj[:finished_at] = (Time.parse(step[:warehousejob][:finishtime]) rescue nil)