16663: Merge branch 'master'
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
index 94990eee16ca2bd4f6d78c822e0f7a6d936b18a8..1d75f584334ee944837183f27f6efc9f9d66c68d 100644 (file)
@@ -1,51 +1,80 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 class PipelineInstanceWorkUnit < ProxyWorkUnit
   def children
+    return @my_children if @my_children
+
     items = []
 
     jobs = {}
-    results = Job.where(uuid: self.proxied.job_ids.values).results
+    results = Job.where(uuid: @proxied.job_ids.values).with_count("none").results
     results.each do |j|
       jobs[j.uuid] = j
     end
 
-    components = self.proxied.components
+    components = get(:components)
     components.each do |name, c|
       if c.is_a?(Hash)
         job = c[:job]
-        if job and job[:uuid] and jobs[job[:uuid]]
-          items << jobs[job[:uuid]].work_unit(name)
+        if job
+          if job[:uuid] and jobs[job[:uuid]]
+            items << jobs[job[:uuid]].work_unit(name)
+          else
+            items << JobWorkUnit.new(job, name, uuid)
+          end
         else
-          items << ProxyWorkUnit.new(c, name)
+          items << JobWorkUnit.new(c, name, uuid)
         end
+      else
+        @unreadable_children = true
+        break
       end
     end
 
-    items
+    @my_children = items
   end
 
-  def progress
-    if self.proxied.state == 'Complete'
-      return 1.0
-    end
-
-    done = 0
-    failed = 0
-    todo = 0
-    children.each do |c|
-      if c.success?.nil?
-        todo = todo+1
-      elsif c.success?
-        done = done+1
-      else
-        failed = failed+1
+  def outputs
+    items = []
+    components = get(:components)
+    components.each do |name, c|
+      if c.is_a?(Hash)
+        items << c[:output_uuid] if c[:output_uuid]
       end
     end
+    items
+  end
+
+  def uri
+    uuid = get(:uuid)
+    "/pipeline_instances/#{uuid}"
+  end
+
+  def title
+    "pipeline"
+  end
 
-    if done + failed + todo > 0
-      total = done + failed + todo
-      (done+failed).to_f / total
-    else
-      0.0
+  def template_uuid
+    get(:pipeline_template_uuid)
+  end
+
+  def state_label
+    if get(:state) != "Failed"
+      return super
+    end
+    if get(:components_summary).andand[:failed].andand > 0
+      return super
+    end
+    # Show "Cancelled" instead of "Failed" if there are no failed
+    # components. #12840
+    get(:components).each do |_, c|
+      jstate = c[:job][:state] rescue nil
+      if jstate == "Failed"
+        return "Failed"
+      end
     end
+    "Cancelled"
   end
 end