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 resource_class = ArvadosBase::resource_class_for_uuid(uuid)
178 resource_class.where(uuid: [uuid]).first rescue nil
182 if state_label.in? ["Complete", "Failed", "Cancelled"]
185 logCollection = Collection.find? lc
187 ApplicationController.helpers.link_to("Log", "#{uri}#Log")
192 elsif state_label == "Running"
194 ApplicationController.helpers.link_to("Log", "#{uri}#Log")
202 if state_label != "Queued"
204 ((if finished_at then finished_at else Time.now() end) - started_at)
210 if state_label != "Queued"
212 (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
218 if state_label == "Queued"
219 Time.now - Time.parse(created_at.to_s)
224 state_label == 'Running'
228 state_label == 'Paused'
232 state_label.in? ["Complete", "Failed", "Cancelled"]
236 state_label == 'Failed'
240 runningtime = ApplicationController.helpers.determine_wallclock_runtime(if children.any? then children else [self] end)
244 walltime = if finished_at then (finished_at - started_at) else (Time.now - started_at) end
250 resp << "This #{title} started at "
251 resp << ApplicationController.helpers.render_localized_date(started_at)
253 if state_label == 'Complete'
254 resp << "completed in "
255 elsif state_label == 'Failed'
256 resp << "failed after "
258 resp << "has been active for "
261 if walltime > runningtime
262 resp << ApplicationController.helpers.render_time(walltime, false)
264 resp << ApplicationController.helpers.render_time(runningtime, false)
269 resp << ApplicationController.helpers.render_localized_date(finished_at)
274 resp << "This #{title} is "
275 resp << if state_label == 'Running' then 'active' else state_label.downcase end
281 resp << " Check the Log tab for more detail about why it failed."
288 if state_label == 'Running'
297 cpu_time = children.map { |c|
299 (c.runtime_constraints.andand[:min_nodes] || 1) * ((c.finished_at || Time.now()) - c.started_at)
306 cpu_time = (runtime_constraints.andand[:min_nodes] || 1) * ((finished_at || Time.now()) - started_at)
310 resp << ApplicationController.helpers.render_time(runningtime, false)
311 if (walltime - runningtime) > 0
313 resp << ApplicationController.helpers.render_time(walltime - runningtime, false)
320 resp << ApplicationController.helpers.render_time(cpu_time, false)
321 resp << " of node allocation time ("
322 resp << (cpu_time/runningtime).round(1).to_s
323 resp << "⨯ scaling)."
335 def live_log_lines(limit)
336 Log.where(object_uuid: log_object_uuids).
337 order("created_at DESC").
339 select { |log| log.properties[:text].is_a? String }.
341 flat_map { |log| log.properties[:text].split("\n") }
346 def get key, obj=@proxied
347 if obj.respond_to? key
349 elsif obj.is_a?(Hash)