Merge branch '11644-mounts-api'
[arvados.git] / apps / workbench / app / models / job.rb
index 173d3a06964fb5667b9546aee4bab518baf3c190..128440d52612c7b748eb91da7f14fba640045d0b 100644 (file)
@@ -1,17 +1,59 @@
 class Job < ArvadosBase
-  def self.goes_in_folders?
+  def self.goes_in_projects?
     true
   end
 
-  def attribute_editable? attr, *args
-    false
+  def content_summary
+    "#{script} job"
   end
 
-  def self.creatable?
-    false
+  def editable_attributes
+    %w(description)
+  end
+
+  def default_name
+    if script
+      x = "\"#{script}\" job"
+    else
+      x = super
+    end
+    if finished_at
+      x += " finished #{finished_at.strftime('%b %-d')}"
+    elsif started_at
+      x += " started #{started_at.strftime('%b %-d')}"
+    elsif created_at
+      x += " submitted #{created_at.strftime('%b %-d')}"
+    end
   end
 
   def cancel
-    arvados_api_client.api "jobs/#{self.uuid}/", "cancel", {}
+    arvados_api_client.api "jobs/#{self.uuid}/", "cancel", {"cascade" => true}
+  end
+
+  def self.queue_size
+    arvados_api_client.api("jobs/", "queue_size", {"_method"=> "GET"})[:queue_size] rescue 0
+  end
+
+  def self.queue
+    arvados_api_client.unpack_api_response arvados_api_client.api("jobs/", "queue", {"_method"=> "GET"})
+  end
+
+  def textile_attributes
+    [ 'description' ]
+  end
+
+  def stderr_log_query(limit=nil)
+    query = Log.where(object_uuid: self.uuid).order("created_at DESC").with_count('none')
+    query = query.limit(limit) if limit
+    query
+  end
+
+  def stderr_log_lines(limit=2000)
+    stderr_log_query(limit).results.reverse.
+      flat_map { |log| log.properties[:text].split("\n") rescue [] }
+  end
+
+  def work_unit(label=nil)
+    JobWorkUnit.new(self, label, self.uuid)
   end
 end