Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / models / job_work_unit.rb
index 6bef50f4caabc070f232e1aa66a5a3da5a599e19..83825a533849fea023482d12bafeac8c88db76d8 100644 (file)
@@ -1,64 +1,97 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 class JobWorkUnit < ProxyWorkUnit
   def children
-    # Job tasks
-    uuid = (self.proxied.uuid if self.proxied.respond_to?(:uuid)) || self.proxied[:uuid]
-    tasks = JobTask.filter([['job_uuid', '=', uuid]]).results
+    return @my_children if @my_children
+
+    # Jobs components
     items = []
-    tasks.each do |t|
-      items << t.work_unit("task #{items.size}")
-    end
+    components = get(:components)
+    uuids = components.andand.collect {|_, v| v}
+    return items if (!uuids or uuids.empty?)
 
-    # Jobs submitted by this job  --  TBD
+    rcs = {}
+    uuids.each do |u|
+      r = ArvadosBase::resource_class_for_uuid(u)
+      rcs[r] = [] unless rcs[r]
+      rcs[r] << u
+    end
+    rcs.each do |rc, ids|
+      rc.where(uuid: ids).each do |obj|
+        items << obj.work_unit(components.key(obj.uuid))
+      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
-
-    tasks_summary = (self.proxied.tasks_summary if self.proxied.respond_to?(:tasks_summary)) || self.proxied[:tasks_summary]
-    failed = tasks_summary[:failed] || 0 rescue 0
-    done = tasks_summary[:done] || 0 rescue 0
-    running = tasks_summary[:running] || 0 rescue 0
-    todo = tasks_summary[:todo] || 0 rescue 0
-    if done + running + failed + todo > 0
-      total_tasks = done + running + failed + todo
-      (done+failed).to_f / total_tasks
+  def child_summary
+    if children.any?
+      super
     else
-      0.0
+      get(:tasks_summary)
     end
   end
 
+  def parameters
+    get(:script_parameters)
+  end
+
+  def repository
+    get(:repository)
+  end
+
+  def script
+    get(:script)
+  end
+
+  def script_version
+    get(:script_version)
+  end
+
+  def supplied_script_version
+    get(:supplied_script_version)
+  end
+
   def docker_image
-    (self.proxied.docker_image_locator if self.proxied.respond_to?(:docker_image_locator)) || self.proxied[:docker_image_locator]
+    get(:docker_image_locator)
   end
 
   def nondeterministic
-    (self.proxied.nondeterministic if self.proxied.respond_to?(:nondeterministic)) || self.proxied[:nondeterministic]
+    get(:nondeterministic)
+  end
+
+  def runtime_constraints
+    get(:runtime_constraints)
   end
 
   def priority
-    (self.proxied.priority if self.proxied.respond_to?(:priority)) || self.proxied[:priority]
+    get(:priority)
   end
 
   def log_collection
-    (self.proxied.log if self.proxied.respond_to?(:log)) || self.proxied[:log]
+    get(:log)
   end
 
-  def output
-    (self.proxied.output if self.proxied.respond_to?(:output)) || self.proxied[:output]
+  def outputs
+    items = []
+    items << get(:output) if get(:output)
+    items
   end
 
-  def uri
-    uuid = (self.proxied.uuid if self.proxied.respond_to?(:uuid)) || self.proxied[:uuid]
-    "/jobs/#{uuid}"
+  def can_cancel?
+    state_label.in? ["Queued", "Running"]
   end
 
-  def child_summary
-    (self.proxied.tasks_summary if self.proxied.respond_to?(:tasks_summary)) || self.proxied[:tasks_summary]
+  def confirm_cancellation
+    "All unfinished child jobs and pipelines will also be canceled, even if they are being used in another job or pipeline. Are you sure you want to cancel this job?"
+  end
+
+  def uri
+    uuid = get(:uuid)
+    "/jobs/#{uuid}"
   end
 
   def title