8876: For jobs also, compute progress from it's children if present; otherwise, use...
[arvados.git] / apps / workbench / app / models / job_work_unit.rb
1 class JobWorkUnit < ProxyWorkUnit
2   def children
3     return self.my_children if self.my_children
4
5     # Jobs components
6     items = []
7     components = get(:components)
8     uuids = components.andand.collect {|_, v| v}
9     return items if (!uuids or uuids.empty?)
10
11     rcs = {}
12     uuids.each do |u|
13       r = ArvadosBase::resource_class_for_uuid(u)
14       rcs[r] = [] unless rcs[r]
15       rcs[r] << u
16     end
17     rcs.each do |rc, ids|
18       rc.where(uuid: ids).each do |obj|
19         items << obj.work_unit(components.key(obj.uuid))
20       end
21     end
22
23     self.my_children = items
24   end
25
26   def docker_image
27     get(:docker_image_locator)
28   end
29
30   def nondeterministic
31     get(:nondeterministic)
32   end
33
34   def priority
35     get(:priority)
36   end
37
38   def log_collection
39     get(:log)
40   end
41
42   def output
43     get(:output)
44   end
45
46   def child_summary
47     if children.any?
48       super
49     else
50       get(:tasks_summary)
51     end
52   end
53
54   def can_cancel?
55     true
56   end
57
58   def uri
59     uuid = get(:uuid)
60     "/jobs/#{uuid}"
61   end
62
63   def title
64     "job"
65   end
66 end