5737: Merge branch 'master' into 5737-ruby231
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
index 3f8c9a2baaf2cca40062ec7c03f7d2793113881e..293a77c099d829ae58e58d07784932ba1e9c5fdf 100644 (file)
@@ -1,55 +1,58 @@
 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.work_unit("job #{items.size}")
+      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]]
+        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
 
-    if done + failed + todo > 0
-      total = done + failed + todo
-      (done+failed).to_f / total
-    else
-      0.0
-    end
+  def uri
+    uuid = get(:uuid)
+    "/pipeline_instances/#{uuid}"
+  end
+
+  def title
+    "pipeline"
   end
 
-  def log_collection
-    self.proxied.job_log_ids
+  def template_uuid
+    get(:pipeline_template_uuid)
   end
 end