Merge branch '10649-squeue-stderr' closes #10649
[arvados.git] / apps / workbench / app / models / container_work_unit.rb
index 43871c51515a2b63d004cee099e6caa368cff2c8..ed82f18036c1025bffb16e5267701045039bb167 100644 (file)
@@ -1,7 +1,7 @@
 class ContainerWorkUnit < ProxyWorkUnit
   attr_accessor :container
 
-  def initialize proxied, label
+  def initialize proxied, label, parent
     super
     if @proxied.is_a?(ContainerRequest)
       container_uuid = get(:container_uuid)
@@ -12,7 +12,7 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def children
-    return self.my_children if self.my_children
+    return @my_children if @my_children
 
     container_uuid = nil
     container_uuid = if @proxied.is_a?(Container) then uuid else get(:container_uuid) end
@@ -25,7 +25,7 @@ class ContainerWorkUnit < ProxyWorkUnit
       end
     end
 
-    self.my_children = items
+    @my_children = items
   end
 
   def title
@@ -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,14 +79,15 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def state_label
-    if @proxied.is_a? ContainerRequest and
-       get(:state) == "Committed" and
-       get(:state, @container) == "Complete" and
-       get(:exit_code, @container) != 0
-      "Failed"
-    else
-      get_combined(:state)
-    end
+    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
@@ -93,17 +98,22 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:runtime_constraints)
   end
 
-  def priority
-    get_combined(:priority)
-  end
-
   def log_collection
-    get_combined(:log)
+    if @proxied.is_a?(ContainerRequest)
+      get(:log_uuid)
+    else
+      get(:log)
+    end
   end
 
   def outputs
     items = []
-    items << get_combined(:output) if get_combined(:output)
+    if @proxied.is_a?(ContainerRequest)
+      out = get(:output_uuid)
+    else
+      out = get(:output)
+    end
+    items << out if out
     items
   end
 
@@ -132,14 +142,7 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def log_object_uuids
-    [get_combined(:uuid), get(:uuid)].uniq
-  end
-
-  def live_log_lines(limit=2000)
-    event_types = ["stdout", "stderr", "arv-mount", "crunch-run"]
-    log_lines = Log.where(event_type: event_types, object_uuid: log_object_uuids).order("id DESC").limit(limit)
-    log_lines.results.reverse.
-      flat_map { |log| log.properties[:text].split("\n") rescue [] }
+    [get(:uuid, @container), get(:uuid, @proxied)].compact
   end
 
   def render_log
@@ -149,7 +152,14 @@ class ContainerWorkUnit < ProxyWorkUnit
     end
   end
 
-  # End combined propeties
+  def template_uuid
+    properties = get(:properties)
+    if properties
+      properties[:template_uuid]
+    end
+  end
+
+  # End combined properties
 
   protected
   def get_combined key