Merge branch '10081-cwl-run-same-job' into 9988-cwl-arv-hints
[arvados.git] / apps / workbench / app / models / container_work_unit.rb
index 037a6e53eebceaa2e45ea964126a65c33afe1a17..b6e72dc526538d022166d52ff0a342373bb585cc 100644 (file)
@@ -46,13 +46,17 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def can_cancel?
-    @proxied.is_a?(ContainerRequest) && state_label.in?(["Queued", "Locked", "Running"]) && priority > 0
+    @proxied.is_a?(ContainerRequest) && @proxied.state == "Committed" && @proxied.priority > 0 && @proxied.editable?
   end
 
   def container_uuid
     get(:container_uuid)
   end
 
+  def priority
+    @proxied.priority
+  end
+
   # For the following properties, use value from the @container if exists
   # This applies to a ContainerRequest with container_uuid
 
@@ -75,7 +79,15 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def state_label
-    get_combined(:state)
+    ec = exit_code
+    return "Failed" if (ec && ec != 0)
+    state = get_combined(:state)
+    return "Ready" if ((priority == 0) and (["Queued", "Locked"].include?(state)))
+    state
+  end
+
+  def exit_code
+    get_combined(:exit_code)
   end
 
   def docker_image
@@ -86,10 +98,6 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:runtime_constraints)
   end
 
-  def priority
-    get_combined(:priority)
-  end
-
   def log_collection
     get_combined(:log)
   end
@@ -124,7 +132,25 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:output_path)
   end
 
-  # End combined propeties
+  def log_object_uuids
+    [get(:uuid, @container), get(:uuid, @proxied)].compact
+  end
+
+  def render_log
+    collection = Collection.find(log_collection) rescue nil
+    if collection
+      return {log: collection, partial: 'collections/show_files', locals: {object: collection, no_checkboxes: true}}
+    end
+  end
+
+  def template_uuid
+    properties = get(:properties)
+    if properties
+      properties[:template_uuid]
+    end
+  end
+
+  # End combined properties
 
   protected
   def get_combined key