1 class ProxyWorkUnit < WorkUnit
6 attr_accessor :my_children
7 attr_accessor :unreadable_children
9 def initialize proxied, label, parent
27 def modified_by_user_uuid
28 get(:modified_by_user_uuid)
37 t = Time.parse(t) if (t.is_a? String)
43 t = Time.parse(t) if (t.is_a? String)
49 t = Time.parse(t) if (t.is_a? String)
55 t = Time.parse(t) if (t.is_a? String)
61 if ["Running", "RunningOnServer", "RunningOnClient"].include? state
70 def state_bootstrap_class
75 when 'Failed', 'Cancelled'
77 when 'Running', 'RunningOnServer', 'RunningOnClient'
86 if state == 'Complete'
88 elsif state == 'Failed' or state == 'Cancelled'
104 when 'Failed', 'Cancelled'
114 summary[:done] = done
115 summary[:failed] = failed
116 summary[:todo] = todo
117 summary[:running] = running
121 def child_summary_str
122 summary = child_summary
125 if state_label == 'Running'
126 done = summary[:done] || 0
127 running = summary[:running] || 0
128 failed = summary[:failed] || 0
129 todo = summary[:todo] || 0
130 total = done + running + failed + todo
133 summary_txt += "#{summary[:done]} #{'child'.pluralize(summary[:done])} done,"
134 summary_txt += "#{summary[:failed]} failed,"
135 summary_txt += "#{summary[:running]} running,"
136 summary_txt += "#{summary[:todo]} pending"
144 if state == 'Complete'
146 elsif state == 'Failed' or state == 'Cancelled'
150 summary = child_summary
151 return 0.0 if summary.nil?
153 done = summary[:done] || 0
154 running = summary[:running] || 0
155 failed = summary[:failed] || 0
156 todo = summary[:todo] || 0
157 total = done + running + failed + todo
159 (done+failed).to_f / total
177 def has_unreadable_children
182 if state_label != "Queued"
184 ((if finished_at then finished_at else Time.now() end) - started_at)
190 if state_label != "Queued"
192 (runtime_constraints.andand[:min_nodes] || 1).to_i * ((finished_at || Time.now()) - started_at)
198 if state_label == "Queued"
199 Time.now - Time.parse(created_at.to_s)
204 state_label == 'Running'
208 state_label == 'Paused'
212 state_label.in? ["Complete", "Failed", "Cancelled"]
216 state_label == 'Failed'
220 runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] end)
224 walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end
230 resp << "This #{title} started at "
231 resp << ApplicationController.helpers.render_localized_date(started_at)
233 if state_label == 'Complete'
234 resp << "completed in "
235 elsif state_label == 'Failed'
236 resp << "failed after "
238 resp << "has been active for "
241 if walltime > runningtime
242 resp << ApplicationController.helpers.render_time(walltime, false)
244 resp << ApplicationController.helpers.render_time(runningtime, false)
249 resp << ApplicationController.helpers.render_localized_date(finished_at)
254 resp << "This #{title} is "
255 resp << if state_label == 'Running' then 'active' else state_label.downcase end
261 resp << " Check the Log tab for more detail about why it failed."
268 if state_label == 'Running'
277 cpu_time = children.map { |c|
279 (c.runtime_constraints.andand[:min_nodes] || 1).to_i * ((c.finished_at || Time.now()) - c.started_at)
286 cpu_time = (runtime_constraints.andand[:min_nodes] || 1).to_i * ((finished_at || Time.now()) - started_at)
290 resp << ApplicationController.helpers.render_time(runningtime, false)
291 if (walltime - runningtime) > 0
293 resp << ApplicationController.helpers.render_time(walltime - runningtime, false)
300 resp << ApplicationController.helpers.render_time(cpu_time, false)
301 resp << " of node allocation time ("
302 resp << (cpu_time/runningtime).round(1).to_s
303 resp << "⨯ scaling)."
315 def live_log_lines(limit)
316 Log.where(object_uuid: log_object_uuids).
317 order("created_at DESC").
319 select { |log| log.properties[:text].is_a? String }.
321 flat_map { |log| log.properties[:text].split("\n") }
326 def get key, obj=@proxied
327 if obj.respond_to? key
329 elsif obj.is_a?(Hash)
330 obj[key] || obj[key.to_s]