Permalink
Browse files

Support setting a default priority for new jobs

  • Loading branch information...
1 parent 8cb550b commit ab8bbc10ae374d9b1f5ce6e2f4dedf8dca3d5a70 @codekitchen codekitchen committed Sep 22, 2010
Showing with 15 additions and 3 deletions.
  1. +3 −0 lib/delayed/backend/active_record.rb
  2. +2 −2 lib/delayed/backend/base.rb
  3. +10 −1 spec/shared_backend_spec.rb
@@ -23,6 +23,9 @@ class Job < ::ActiveRecord::Base
include Delayed::Backend::Base
set_table_name :delayed_jobs
+ cattr_accessor :default_priority
+ self.default_priority = 0
+
named_scope :ready_to_run, lambda {|worker_name, max_run_time|
{:conditions => ['(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL', db_time_now, db_time_now - max_run_time, worker_name]}
}
@@ -21,7 +21,7 @@ def enqueue(*args)
end
options = args.first || {}
- options[:priority] ||= 0
+ options[:priority] ||= self.default_priority
options[:payload_object] = object
options[:queue] ||= Delayed::Worker.queue
self.create(options)
@@ -101,4 +101,4 @@ def before_save
end
end
-end
+end
@@ -30,6 +30,15 @@ def create_job(opts = {})
@job.priority.should == 5
end
+ it "should use the default priority when enqueuing items" do
+ @job = @backend.enqueue SimpleJob.new
+ @job.priority.should == 0
+ @backend.default_priority = 10
+ @job = @backend.enqueue SimpleJob.new
+ @job.priority.should == 10
+ @backend.default_priority = 0
+ end
+
it "should be able to set run_at when enqueuing items" do
later = @backend.db_time_now + 5.minutes
@job = @backend.enqueue SimpleJob.new, :priority => 5, :run_at => later
@@ -220,4 +229,4 @@ def create_job(opts = {})
end
end
-end
+end

0 comments on commit ab8bbc1

Please sign in to comment.