Merge branch '16104-select-uuid'
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class PipelineInstanceWorkUnit < ProxyWorkUnit
6   def children
7     return @my_children if @my_children
8
9     items = []
10
11     jobs = {}
12     results = Job.where(uuid: @proxied.job_ids.values).with_count("none").results
13     results.each do |j|
14       jobs[j.uuid] = j
15     end
16
17     components = get(:components)
18     components.each do |name, c|
19       if c.is_a?(Hash)
20         job = c[:job]
21         if job
22           if job[:uuid] and jobs[job[:uuid]]
23             items << jobs[job[:uuid]].work_unit(name)
24           else
25             items << JobWorkUnit.new(job, name, uuid)
26           end
27         else
28           items << JobWorkUnit.new(c, name, uuid)
29         end
30       else
31         @unreadable_children = true
32         break
33       end
34     end
35
36     @my_children = items
37   end
38
39   def outputs
40     items = []
41     components = get(:components)
42     components.each do |name, c|
43       if c.is_a?(Hash)
44         items << c[:output_uuid] if c[:output_uuid]
45       end
46     end
47     items
48   end
49
50   def uri
51     uuid = get(:uuid)
52     "/pipeline_instances/#{uuid}"
53   end
54
55   def title
56     "pipeline"
57   end
58
59   def template_uuid
60     get(:pipeline_template_uuid)
61   end
62
63   def state_label
64     if get(:state) != "Failed"
65       return super
66     end
67     if get(:components_summary).andand[:failed].andand > 0
68       return super
69     end
70     # Show "Cancelled" instead of "Failed" if there are no failed
71     # components. #12840
72     get(:components).each do |_, c|
73       jstate = c[:job][:state] rescue nil
74       if jstate == "Failed"
75         return "Failed"
76       end
77     end
78     "Cancelled"
79   end
80 end