Merge branch '10029-wb-send-request-id'
[arvados.git] / apps / workbench / app / models / container_work_unit.rb
index e56c0655234cb598aecaf917abb3c3cca59f3156..be526ca98796f9d99b200c68dbc312cdc6ec6aad 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,9 +79,15 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def state_label
+    ec = exit_code
+    return "Failed" if (ec && ec != 0)
     get_combined(:state)
   end
 
+  def exit_code
+    get_combined(:exit_code)
+  end
+
   def docker_image
     get_combined(:container_image)
   end
@@ -86,10 +96,6 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:runtime_constraints)
   end
 
-  def priority
-    get_combined(:priority)
-  end
-
   def log_collection
     get_combined(:log)
   end
@@ -125,14 +131,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 +148,7 @@ class ContainerWorkUnit < ProxyWorkUnit
     end
   end
 
-  # End combined propeties
+  # End combined properties
 
   protected
   def get_combined key