8460: Merge branch 'master' into 8460-websocket-go
[arvados.git] / apps / workbench / app / models / job_work_unit.rb
1 class JobWorkUnit < ProxyWorkUnit
2   def children
3     return @my_children if @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     @my_children = items
24   end
25
26   def child_summary
27     if children.any?
28       super
29     else
30       get(:tasks_summary)
31     end
32   end
33
34   def parameters
35     get(:script_parameters)
36   end
37
38   def repository
39     get(:repository)
40   end
41
42   def script
43     get(:script)
44   end
45
46   def script_version
47     get(:script_version)
48   end
49
50   def supplied_script_version
51     get(:supplied_script_version)
52   end
53
54   def docker_image
55     get(:docker_image_locator)
56   end
57
58   def nondeterministic
59     get(:nondeterministic)
60   end
61
62   def runtime_constraints
63     get(:runtime_constraints)
64   end
65
66   def priority
67     get(:priority)
68   end
69
70   def log_collection
71     get(:log)
72   end
73
74   def outputs
75     items = []
76     items << get(:output) if get(:output)
77     items
78   end
79
80   def can_cancel?
81     state_label.in? ["Queued", "Running"]
82   end
83
84   def uri
85     uuid = get(:uuid)
86     "/jobs/#{uuid}"
87   end
88
89   def title
90     "job"
91   end
92 end