[ARVADOS] created: d60536bb1ca0eb6e72388a5287e786725dbdfd9e

git at public.curoverse.com git at public.curoverse.com
Wed Sep 17 09:29:42 EDT 2014


        at  d60536bb1ca0eb6e72388a5287e786725dbdfd9e (commit)


commit d60536bb1ca0eb6e72388a5287e786725dbdfd9e
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Wed Sep 17 09:29:32 2014 -0400

    3605: Add "queue_position" to jobs.  Also add a route on jobs controller to get
    the true size of the job queue.

diff --git a/services/api/app/controllers/arvados/v1/jobs_controller.rb b/services/api/app/controllers/arvados/v1/jobs_controller.rb
index 55e2d73..7b3b658 100644
--- a/services/api/app/controllers/arvados/v1/jobs_controller.rb
+++ b/services/api/app/controllers/arvados/v1/jobs_controller.rb
@@ -2,8 +2,8 @@ class Arvados::V1::JobsController < ApplicationController
   accept_attribute_as_json :script_parameters, Hash
   accept_attribute_as_json :runtime_constraints, Hash
   accept_attribute_as_json :tasks_summary, Hash
-  skip_before_filter :find_object_by_uuid, :only => :queue
-  skip_before_filter :render_404_if_no_object, :only => :queue
+  skip_before_filter :find_object_by_uuid, :only => [:queue, :queue_size]
+  skip_before_filter :render_404_if_no_object, :only => [:queue, :queue_size]
 
   def create
     [:repository, :script, :script_version, :script_parameters].each do |r|
@@ -162,6 +162,12 @@ class Arvados::V1::JobsController < ApplicationController
     index
   end
 
+  def queue_size
+    # Users may not be allowed to see all the jobs in the queue, so provide a
+    # method to get the actual queue length.
+    render :json => {:queue_size => Job.queue.size}
+  end
+
   def self._create_requires_parameters
     (super rescue {}).
       merge({
diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index 32f28e3..e142d8d 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -40,6 +40,7 @@ class Job < ArvadosModel
     t.add :repository
     t.add :supplied_script_version
     t.add :docker_image_locator
+    t.add :queue_position
     t.add :description
   end
 
@@ -55,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')
diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb
index 74d2aea..bcfe9b8 100644
--- a/services/api/config/routes.rb
+++ b/services/api/config/routes.rb
@@ -22,6 +22,7 @@ Server::Application.routes.draw do
       resources :job_tasks
       resources :jobs do
         get 'queue', on: :collection
+        get 'queue_size', on: :collection
         post 'cancel', on: :member
       end
       resources :keep_disks do

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list