Merge branch '10346-rearrange-api-docs' closes #10346
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
index 9d6db39572bd869eeff73f535e10f0dbd4b3cf52..293a77c099d829ae58e58d07784932ba1e9c5fdf 100644 (file)
@@ -1,14 +1,16 @@
 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).results
     results.each do |j|
       jobs[j.uuid] = j
     end
 
-    components = (self.proxied.components if self.proxied.respond_to?(:components)) || self.proxied[:components]
+    components = get(:components)
     components.each do |name, c|
       if c.is_a?(Hash)
         job = c[:job]
@@ -16,56 +18,41 @@ class PipelineInstanceWorkUnit < ProxyWorkUnit
           if job[:uuid] and jobs[job[:uuid]]
             items << jobs[job[:uuid]].work_unit(name)
           else
-            items << JobWorkUnit.new(job, name)
+            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
-    state = (self.proxied.state if self.proxied.respond_to?(:state)) || self.proxied[:state]
-    if 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
-
-    if done + failed + todo > 0
-      total = done + failed + todo
-      (done+failed).to_f / total
-    else
-      0.0
-    end
-  end
-
-  def can_cancel?
-    true
+    items
   end
 
   def uri
-    uuid = (self.proxied.uuid if self.proxied.respond_to?(:uuid)) || self.proxied[:uuid]
+    uuid = get(:uuid)
     "/pipeline_instances/#{uuid}"
   end
 
   def title
     "pipeline"
   end
+
+  def template_uuid
+    get(:pipeline_template_uuid)
+  end
 end