Merge branch 'master' into 3661-copy-move-from-show
[arvados.git] / services / api / app / models / job.rb
index fc445ae24edb5977a2092f7d92af86c300eb21ad..e142d8db08f82a1bc96a7d84559d7b3c36dec050 100644 (file)
@@ -8,6 +8,7 @@ class Job < ArvadosModel
   serialize :tasks_summary, Hash
   before_create :ensure_unique_submit_id
   after_commit :trigger_crunch_dispatch_if_cancelled, :on => :update
+  before_validation :set_priority
   validate :ensure_script_version_is_commit
   validate :find_docker_image_locator
 
@@ -28,7 +29,6 @@ class Job < ArvadosModel
     t.add :started_at
     t.add :finished_at
     t.add :output
-    t.add :output_is_persistent
     t.add :success
     t.add :running
     t.add :is_locked_by_uuid
@@ -40,6 +40,8 @@ class Job < ArvadosModel
     t.add :repository
     t.add :supplied_script_version
     t.add :docker_image_locator
+    t.add :queue_position
+    t.add :description
   end
 
   def assert_finished
@@ -54,6 +56,16 @@ class Job < ArvadosModel
       order('priority desc, created_at')
   end
 
+  def queue_position
+    i = 0
+    Job::queue.each do |j|
+      if j[:uuid] == self.uuid
+        return i
+      end
+    end
+    nil
+  end
+
   def self.running
     self.where('running = ?', true).
       order('priority desc, created_at')
@@ -73,6 +85,13 @@ class Job < ArvadosModel
     super + %w(output log)
   end
 
+  def set_priority
+    if self.priority.nil?
+      self.priority = 0
+    end
+    true
+  end
+
   def ensure_script_version_is_commit
     if self.is_locked_by_uuid and self.started_at
       # Apparently client has already decided to go for it. This is
@@ -118,7 +137,7 @@ class Job < ArvadosModel
       self.docker_image_locator = nil
       true
     elsif coll = Collection.for_latest_docker_image(image_search, image_tag)
-      self.docker_image_locator = coll.uuid
+      self.docker_image_locator = coll.portable_data_hash
       true
     else
       errors.add(:docker_image_locator, "not found for #{image_search}")
@@ -191,7 +210,7 @@ class Job < ArvadosModel
       if self.cancelled_at and not self.cancelled_at_was
         self.cancelled_at = Time.now
         self.cancelled_by_user_uuid = current_user.uuid
-        self.cancelled_by_client_uuid = current_api_client.uuid
+        self.cancelled_by_client_uuid = current_api_client.andand.uuid
         @need_crunch_dispatch_trigger = true
       else
         self.cancelled_at = self.cancelled_at_was