Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / models / pipeline_instance.rb
index b51f07c40b36e0324b09e14c81dbf632dbcd7a68..d481f41c7eab37b0f8ba0192ba9e17438fd3803e 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require "arvados/keep"
 
 class PipelineInstance < ArvadosBase
@@ -13,7 +17,7 @@ class PipelineInstance < ArvadosBase
       template = if lookup and lookup[self.pipeline_template_uuid]
                    lookup[self.pipeline_template_uuid]
                  else
-                   PipelineTemplate.where(uuid: self.pipeline_template_uuid).first
+                   PipelineTemplate.find?(self.pipeline_template_uuid) if self.pipeline_template_uuid
                  end
       if template
         template.name
@@ -103,9 +107,10 @@ class PipelineInstance < ArvadosBase
 
   def stderr_log_query(limit=nil)
     query = Log.
-      where(event_type: "stderr",
-            object_uuid: stderr_log_object_uuids).
-      order("id DESC")
+            with_count('none').
+            where(event_type: "stderr",
+                  object_uuid: stderr_log_object_uuids).
+            order("created_at DESC")
     unless limit.nil?
       query = query.limit(limit)
     end
@@ -122,10 +127,10 @@ class PipelineInstance < ArvadosBase
       Keep::Locator.parse(loc_s)
     end
     if log_pdhs.any? and
-        Collection.where(portable_data_hash: log_pdhs).limit(1).results.any?
+        Collection.where(portable_data_hash: log_pdhs).limit(1).with_count("none").results.any?
       true
     elsif log_uuids.any? and
-        Collection.where(uuid: log_uuids).limit(1).results.any?
+        Collection.where(uuid: log_uuids).limit(1).with_count("none").results.any?
       true
     else
       stderr_log_query(1).results.any?
@@ -133,7 +138,11 @@ class PipelineInstance < ArvadosBase
   end
 
   def work_unit(label=nil)
-    PipelineInstanceWorkUnit.new(self, label || self.name)
+    PipelineInstanceWorkUnit.new(self, label || self.name, self.uuid)
+  end
+
+  def cancel
+    arvados_api_client.api "pipeline_instances/#{self.uuid}/", "cancel", {"cascade" => true}
   end
 
   private