add Jobs#resource_limits attribute. refs #1417
authorTom Clegg <tom@clinicalfuture.com>
Mon, 18 Mar 2013 00:48:25 +0000 (17:48 -0700)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 18 Mar 2013 00:48:56 +0000 (17:48 -0700)
app/controllers/orvos/v1/jobs_controller.rb
app/models/job.rb
db/migrate/20130318002138_add_resource_limits_to_jobs.rb [new file with mode: 0644]
db/schema.rb
script/dispatch_jobs.rb

index 33425eb5d5afb279357547422d617739921330ba..96e22ff49e83dd80a52bfd7bdc47be37eb72fdb3 100644 (file)
@@ -1,2 +1,5 @@
 class Orvos::V1::JobsController < ApplicationController
+  accept_attribute_as_json :command_parameters, Hash
+  accept_attribute_as_json :resource_limits, Hash
+  accept_attribute_as_json :tasks_summary, Hash
 end
index d0173ee4dcbb79a2d87dac5a9b8517bfade41019..e0a096aa61c038d270fd0d41ee5d40ecc321a14f 100644 (file)
@@ -3,6 +3,7 @@ class Job < OrvosModel
   include KindAndEtag
   include CommonApiTemplate
   serialize :command_parameters, Hash
+  serialize :resource_limits, Hash
   serialize :tasks_summary, Hash
   before_create :ensure_unique_submit_id
 
diff --git a/db/migrate/20130318002138_add_resource_limits_to_jobs.rb b/db/migrate/20130318002138_add_resource_limits_to_jobs.rb
new file mode 100644 (file)
index 0000000..f7bd04b
--- /dev/null
@@ -0,0 +1,5 @@
+class AddResourceLimitsToJobs < ActiveRecord::Migration
+  def change
+    add_column :jobs, :resource_limits, :text
+  end
+end
index c5720ea54c6f752900b19190aadcab2bb10cf377..cab044df8c2aeab70524fb9b7fb4d50df98e9937 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130315213205) do
+ActiveRecord::Schema.define(:version => 20130318002138) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",               :null => false
@@ -131,6 +131,7 @@ ActiveRecord::Schema.define(:version => 20130315213205) do
     t.string   "is_locked_by"
     t.string   "log"
     t.text     "tasks_summary"
+    t.text     "resource_limits"
   end
 
   add_index "jobs", ["command"], :name => "index_jobs_on_command"
index 0eea8d57cc2d3a56d2f6c37638676648853f9a88..e39ef311310fc059f91a4b73dd2937c9448439fc 100755 (executable)
@@ -48,7 +48,8 @@ class Dispatcher
 
   def refresh_todo
     @todo = Job.
-      where('started_at is ? and is_locked_by is ?', nil, nil).
+      where('started_at is ? and is_locked_by is ? and cancelled_at is ?',
+            nil, nil, nil).
       order('priority desc, created_at')
   end
 
@@ -86,6 +87,15 @@ class Dispatcher
         cmd_args << "#{k}=#{v}"
       end
       cmd_args << "revision=#{job.command_version}"
+
+      begin
+        cmd_args << "stepspernode=#{job.resource_limits['max_tasks_per_node'].to_i}"
+      rescue
+        # OK if limit is not specified. OK to ignore if not integer.
+      end
+
+      $stderr.puts "dispatch: #{cmd_args.join ' '}"
+
       begin
         i, o, e, t = Open3.popen3(*cmd_args)
       rescue