9687: Added method to access container's exit_code. Updated test to explicitly test...
[arvados.git] / apps / workbench / app / models / container_work_unit.rb
index 037a6e53eebceaa2e45ea964126a65c33afe1a17..248c76351a5d01124b77d450e3e3b8859a3d27d8 100644 (file)
@@ -75,9 +75,15 @@ class ContainerWorkUnit < ProxyWorkUnit
   end
 
   def state_label
+    exit_code = get_combined(:exit_code)
+    return "Failed" if (exit_code && exit_code != 0)
     get_combined(:state)
   end
 
+  def exit_code
+    get_combined(:exit_code)
+  end
+
   def docker_image
     get_combined(:container_image)
   end
@@ -124,6 +130,24 @@ class ContainerWorkUnit < ProxyWorkUnit
     get_combined(:output_path)
   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 [] }
+  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
+
   # End combined propeties
 
   protected