Merge branch '11644-mounts-api'
[arvados.git] / apps / workbench / app / models / job.rb
index f933c07701fdcf781c7c19559b6bb023bf7667be..128440d52612c7b748eb91da7f14fba640045d0b 100644 (file)
@@ -7,16 +7,8 @@ class Job < ArvadosBase
     "#{script} job"
   end
 
-  def attribute_editable? attr, *args
-    if attr.to_sym == :description
-      super && attr.to_sym == :description
-    else
-      false
-    end
-  end
-
-  def self.creatable?
-    false
+  def editable_attributes
+    %w(description)
   end
 
   def default_name
@@ -35,41 +27,33 @@ class Job < ArvadosBase
   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 
+  def self.queue
     arvados_api_client.unpack_api_response arvados_api_client.api("jobs/", "queue", {"_method"=> "GET"})
   end
 
-  # The 'job' parameter can be either a Job model object, or a hash containing
-  # the same fields as a Job object (such as the :job entry of a pipeline
-  # component).
-  def self.state job
-    # This has a valid state method on it so call that
-    if job.respond_to? :state and job.state
-      return job.state
-    end
+  def textile_attributes
+    [ 'description' ]
+  end
 
-    # Figure out the state based on the other fields.
-    if job[:cancelled_at]
-      "Cancelled"
-    elsif job[:success] == false
-      "Failed"
-    elsif job[:success] == true
-      "Complete"
-    elsif job[:running] == true
-      "Running"
-    else
-      "Queued"
-    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 textile_attributes
-    [ 'description' ]
+  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