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)
196 (runtime_constraints.andand[:min_nodes] || 1).to_i * ((finished_at || Time.now()) - started_at)
204 if state_label == "Queued"
205 Time.now - Time.parse(created_at.to_s)
210 state_label == 'Running'
214 state_label == 'Paused'
218 state_label.in? ["Complete", "Failed", "Cancelled"]
222 state_label == 'Failed'
226 runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] end)
230 walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end
236 resp << "This #{title} started at "
237 resp << ApplicationController.helpers.render_localized_date(started_at)
239 if state_label == 'Complete'
240 resp << "completed in "
241 elsif state_label == 'Failed'
242 resp << "failed after "
244 resp << "has been active for "
247 if walltime > runningtime
248 resp << ApplicationController.helpers.render_time(walltime, false)
250 resp << ApplicationController.helpers.render_time(runningtime, false)
255 resp << ApplicationController.helpers.render_localized_date(finished_at)
260 resp << "This #{title} is "
261 resp << if state_label == 'Running' then 'active' else state_label.downcase end
267 resp << " Check the Log tab for more detail about why it failed."
274 if state_label == 'Running'
283 resp << ApplicationController.helpers.render_time(runningtime, false)
284 if (walltime - runningtime) > 0
286 resp << ApplicationController.helpers.render_time(walltime - runningtime, false)
293 resp << ApplicationController.helpers.render_time(cpu_time, false)
294 resp << " of node allocation time ("
295 resp << (cpu_time/runningtime).round(1).to_s
296 resp << "⨯ scaling)."
308 def live_log_lines(limit)
309 Log.where(object_uuid: log_object_uuids).
310 order("created_at DESC").
312 select { |log| log.properties[:text].is_a? String }.
314 flat_map { |log| log.properties[:text].split("\n") }
319 def get key, obj=@proxied
320 if obj.respond_to? key
322 elsif obj.is_a?(Hash)
323 obj[key] || obj[key.to_s]