1 class ProxyWorkUnit < WorkUnit
6 attr_accessor :my_children
7 attr_accessor :unreadable_children
9 def initialize proxied, label
26 def modified_by_user_uuid
27 get(:modified_by_user_uuid)
36 t = Time.parse(t) if (t.is_a? String)
42 t = Time.parse(t) if (t.is_a? String)
48 t = Time.parse(t) if (t.is_a? String)
54 t = Time.parse(t) if (t.is_a? String)
60 if ["Running", "RunningOnServer", "RunningOnClient"].include? state
69 def state_bootstrap_class
74 when 'Failed', 'Cancelled'
76 when 'Running', 'RunningOnServer', 'RunningOnClient'
85 if state == 'Complete'
87 elsif state == 'Failed' or state == 'Cancelled'
103 when 'Failed', 'Cancelled'
113 summary[:done] = done
114 summary[:failed] = failed
115 summary[:todo] = todo
116 summary[:running] = running
120 def child_summary_str
121 summary = child_summary
124 if state_label == 'Running'
125 done = summary[:done] || 0
126 running = summary[:running] || 0
127 failed = summary[:failed] || 0
128 todo = summary[:todo] || 0
129 total = done + running + failed + todo
132 summary_txt += "#{summary[:done]} #{'child'.pluralize(summary[:done])} done,"
133 summary_txt += "#{summary[:failed]} failed,"
134 summary_txt += "#{summary[:running]} running,"
135 summary_txt += "#{summary[:todo]} pending"
143 if state == 'Complete'
145 elsif state == 'Failed' or state == 'Cancelled'
149 summary = child_summary
150 return 0.0 if summary.nil?
152 done = summary[:done] || 0
153 running = summary[:running] || 0
154 failed = summary[:failed] || 0
155 todo = summary[:todo] || 0
156 total = done + running + failed + todo
158 (done+failed).to_f / total
176 def has_unreadable_children
181 if state_label != "Queued"
183 ((if finished_at then finished_at else Time.now() end) - started_at)
189 if state_label != "Queued"
191 (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
197 if state_label == "Queued"
198 Time.now - Time.parse(created_at.to_s)
203 state_label == 'Running'
207 state_label == 'Paused'
211 state_label.in? ["Complete", "Failed", "Cancelled"]
215 state_label == 'Failed'
219 runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] end)
223 walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end
229 resp << "This #{title} started at "
230 resp << ApplicationController.helpers.render_localized_date(started_at)
232 if state_label == 'Complete'
233 resp << "completed in "
234 elsif state_label == 'Failed'
235 resp << "failed after "
237 resp << "has been active for "
240 if walltime > runningtime
241 resp << ApplicationController.helpers.render_time(walltime, false)
243 resp << ApplicationController.helpers.render_time(runningtime, false)
248 resp << ApplicationController.helpers.render_localized_date(finished_at)
253 resp << "This #{title} is "
254 resp << if state_label == 'Running' then 'active' else state_label.downcase end
260 resp << " Check the Log tab for more detail about why it failed."
267 if state_label == 'Running'
276 cpu_time = children.map { |c|
278 (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at)
285 cpu_time = (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
289 resp << ApplicationController.helpers.render_time(runningtime, false)
290 if (walltime - runningtime) > 0
292 resp << ApplicationController.helpers.render_time(walltime - runningtime, false)
299 resp << ApplicationController.helpers.render_time(cpu_time, false)
300 resp << " of node allocation time ("
301 resp << (cpu_time/runningtime).round(1).to_s
302 resp << "⨯ scaling)."
314 def live_log_lines(limit)
315 Log.where(object_uuid: log_object_uuids).
316 order("created_at DESC").
318 select { |log| log.properties[:text].is_a? String }.
320 flat_map { |log| log.properties[:text].split("\n") }
325 def get key, obj=@proxied
326 if obj.respond_to? key
328 elsif obj.is_a?(Hash)
329 obj[key] || obj[key.to_s]