add /arvados/v1/jobs/queue
authorTom Clegg <tom@clinicalfuture.com>
Wed, 22 May 2013 19:10:23 +0000 (12:10 -0700)
committerTom Clegg <tom@clinicalfuture.com>
Wed, 22 May 2013 19:10:23 +0000 (12:10 -0700)
doc/api/Jobs.textile
doc/api/methods.textile
services/api/app/controllers/application_controller.rb
services/api/app/controllers/arvados/v1/jobs_controller.rb
services/api/config/routes.rb

index 8de25030c9484737f93879df6fb94cb88b53322e..c602d9b96e10535026debb5faeffa7eccbffad78 100644 (file)
@@ -18,12 +18,26 @@ See "REST methods for working with Arvados resources":methods.html
 
 API endpoint base: @https://xyzzy.arvados.org/arvados/v1/jobs@
 
-h2. Additional parameters for "Create" method
+h3. Additional parameters for "Create" method
 
 table(table table-bordered table-condensed).
 |*Parameter name*|*Type*|*Description*|
 |allow_duplicate|boolean|If true, a new job is submitted even if an identical job has already been submitted (and has not failed). If false or not supplied, a new job will _not_ be submitted and the existing job will be returned in the API response.|
 
+h3. Queue
+
+<pre>
+GET https://xyzzy.arvados.org/arvados/v1/jobs/queue
+POST https://xyzzy.arvados.org/arvados/v1/jobs/queue
+_method=GET
+where[owner]=xyzzy-tpzed-a4lcehql0dv2u25
+</pre>
+
+&rarr; Job resource list
+
+This method is equivalent to the "index method":methods.html#index, except that the results are restricted to queued jobs (i.e., jobs that have not yet been started or cancelled) and order defaults to queue priority.
+
 h2. Resource
 
 Each job has, in addition to the usual "attributes of Arvados resources":resources.html:
index dcea063ccc848fa42a37e509c5023af8982a573b..63bf46913893447188cf7542a1acc6bf673db8e7 100644 (file)
@@ -9,7 +9,7 @@ h1. REST Methods
 
 (using Group as an example)
 
-h2. Index, list, search
+h2(#index). Index, list, search
 
 <pre>
 GET https://xyzzy.arvados.org/arvados/v1/groups?where[owner]=xyzzy-tpzed-a4lcehql0dv2u25
index fca8809ee63d220597ea8ca57cdabd2697c90cc9..2f142b8a01936b03c3cd349bd3d4b2a49eafc74f 100644 (file)
@@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
   before_filter :login_required, :except => :render_not_found
   before_filter :catch_redirect_hint
 
+  before_filter :load_where_param, :only => :index
   before_filter :find_objects_for_index, :only => :index
   before_filter :find_object_by_uuid, :except => [:index, :create]
 
@@ -88,6 +89,11 @@ class ApplicationController < ActionController::Base
 
   protected
 
+  def load_where_param
+    @where = params[:where] || {}
+    @where = Oj.load(@where) if @where.is_a?(String)
+  end
+
   def find_objects_for_index
     uuid_list = [current_user.uuid, *current_user.groups_i_can(:read)]
     sanitized_uuid_list = uuid_list.
@@ -98,9 +104,7 @@ class ApplicationController < ActionController::Base
             true, current_user.is_admin,
             uuid_list,
             current_user.uuid)
-    @where = params[:where] || {}
-    @where = Oj.load(@where) if @where.is_a?(String)
-    if params[:where]
+    if !@where.empty?
       conditions = ['1=1']
       @where.each do |attr,value|
         if attr == 'any'
index 6fbf0fb1bb1c7f30341450ce269eeb7a8a2c3e8b..572a2c18fc84dab8de0dbe79a260fa56a82f42a6 100644 (file)
@@ -2,6 +2,7 @@ class Arvados::V1::JobsController < ApplicationController
   accept_attribute_as_json :script_parameters, Hash
   accept_attribute_as_json :resource_limits, Hash
   accept_attribute_as_json :tasks_summary, Hash
+  skip_before_filter :find_object_by_uuid, :only => :queue
 
   def index
     want_ancestor = @where[:script_version_descends_from]
@@ -38,4 +39,16 @@ class Arvados::V1::JobsController < ApplicationController
     end
     super
   end
+
+  def queue
+    load_where_param
+    @where.merge!({
+                    started_at: nil,
+                    is_locked_by: nil,
+                    cancelled_at: nil
+                  })
+    params[:order] ||= 'priority desc, created_at'
+    find_objects_for_index
+    index
+  end
 end
index 362b5cd06ab22ede74faf6a7675b80fd831b1243..e0b89e0b1f24389b6f89dea9dfc73fb4f6d43fc1 100644 (file)
@@ -79,6 +79,7 @@ Server::Application.routes.draw do
       match '/keep_disks/ping' => 'keep_disks#ping', :as => :ping_keep_disk
       match '/links/from/:tail_uuid' => 'links#index', :as => :arvados_v1_links_from
       match '/users/current' => 'users#current'
+      match '/jobs/queue' => 'jobs#queue'
       resources :collections
       resources :links
       resources :nodes