1 class ProxyWorkUnit < WorkUnit
6 attr_accessor :my_children
7 attr_accessor :unreadable_children
9 def initialize proxied, label
22 def modified_by_user_uuid
23 get(:modified_by_user_uuid)
32 t = Time.parse(t) if (t.is_a? String)
38 t = Time.parse(t) if (t.is_a? String)
44 t = Time.parse(t) if (t.is_a? String)
50 t = Time.parse(t) if (t.is_a? String)
56 if ["Running", "RunningOnServer", "RunningOnClient"].include? state
65 def state_bootstrap_class
70 when 'Failed', 'Cancelled'
72 when 'Running', 'RunningOnServer', 'RunningOnClient'
81 if state == 'Complete'
83 elsif state == 'Failed' or state == 'Cancelled'
99 when 'Failed', 'Cancelled'
109 summary[:done] = done
110 summary[:failed] = failed
111 summary[:todo] = todo
112 summary[:running] = running
116 def child_summary_str
117 summary = child_summary
120 if state_label == 'Running'
121 done = summary[:done] || 0
122 running = summary[:running] || 0
123 failed = summary[:failed] || 0
124 todo = summary[:todo] || 0
125 total = done + running + failed + todo
128 summary_txt += "#{summary[:done]} #{'child'.pluralize(summary[:done])} done,"
129 summary_txt += "#{summary[:failed]} failed,"
130 summary_txt += "#{summary[:running]} running,"
131 summary_txt += "#{summary[:todo]} pending"
139 if state == 'Complete'
141 elsif state == 'Failed' or state == 'Cancelled'
145 summary = child_summary
146 return 0.0 if summary.nil?
148 done = summary[:done] || 0
149 running = summary[:running] || 0
150 failed = summary[:failed] || 0
151 todo = summary[:todo] || 0
152 total = done + running + failed + todo
154 (done+failed).to_f / total
172 def has_unreadable_children
177 if state_label != "Queued"
179 ((if finished_at then finished_at else Time.now() end) - started_at)
185 if state_label != "Queued"
187 (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
193 if state_label == "Queued"
194 Time.now - Time.parse(created_at.to_s)
199 state_label == 'Running'
203 state_label == 'Paused'
207 state_label.in? ["Complete", "Failed", "Cancelled"]
211 state_label == 'Failed'
215 runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] end)
219 walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end
225 resp << "This #{title} started at "
226 resp << ApplicationController.helpers.render_localized_date(started_at)
228 if state_label == 'Complete'
229 resp << "completed in "
230 elsif state_label == 'Failed'
231 resp << "failed after "
233 resp << "has been active for "
236 if walltime > runningtime
237 resp << ApplicationController.helpers.render_time(walltime, false)
239 resp << ApplicationController.helpers.render_time(runningtime, false)
244 resp << ApplicationController.helpers.render_localized_date(finished_at)
249 resp << "This #{title} is "
250 resp << if state_label == 'Running' then 'active' else state_label.downcase end
256 resp << " Check the Log tab for more detail about why it failed."
263 if state_label == 'Running'
272 cpu_time = children.map { |c|
274 (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at)
281 cpu_time = (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
285 resp << ApplicationController.helpers.render_time(runningtime, false)
286 if (walltime - runningtime) > 0
288 resp << ApplicationController.helpers.render_time(walltime - runningtime, false)
295 resp << ApplicationController.helpers.render_time(cpu_time, false)
296 resp << " of node allocation time ("
297 resp << (cpu_time/runningtime).round(1).to_s
298 resp << "⨯ scaling)."
310 def live_log_lines(limit)
311 Log.where(object_uuid: log_object_uuids).
312 order("created_at DESC").
314 select { |log| log.properties[:text].is_a? String }.
316 flat_map { |log| log.properties[:text].split("\n") }
321 def get key, obj=@proxied
322 if obj.respond_to? key
324 elsif obj.is_a?(Hash)