8fc328585712f8c9a51fd3628f9c2446ae75afea
[arvados.git] / apps / workbench / app / models / job_work_unit.rb
1 class JobWorkUnit < ProxyWorkUnit
2   def children
3     uuid = get(:uuid)
4     items = []
5
6     # Jobs components
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     items
23   end
24
25   def progress
26     state = get(:state)
27     if state == 'Complete'
28       return 1.0
29     end
30
31     tasks_summary = get(:tasks_summary)
32     failed = tasks_summary[:failed] || 0 rescue 0
33     done = tasks_summary[:done] || 0 rescue 0
34     running = tasks_summary[:running] || 0 rescue 0
35     todo = tasks_summary[:todo] || 0 rescue 0
36     if done + running + failed + todo > 0
37       total_tasks = done + running + failed + todo
38       (done+failed).to_f / total_tasks
39     else
40       0.0
41     end
42   end
43
44   def docker_image
45     get(:docker_image_locator)
46   end
47
48   def nondeterministic
49     get(:nondeterministic)
50   end
51
52   def priority
53     get(:priority)
54   end
55
56   def log_collection
57     get(:log)
58   end
59
60   def output
61     get(:output)
62   end
63
64   def child_summary
65     get(:tasks_summary)
66   end
67
68   def can_cancel?
69     true
70   end
71
72   def uri
73     uuid = get(:uuid)
74     "/jobs/#{uuid}"
75   end
76
77   def title
78     "job"
79   end
80 end