Permalink
Browse files

Reverse priority so the jobs table can be indexed. Lower numbers have…

… higher priority. The default priority is 0, so increase it for jobs that are not important.

  Delayed::Job.enqueue MyHighPriorityJob.new, 0
  Delayed::Job.enqueue MyLowPriorityJob.new, 20
  • Loading branch information...
1 parent 601947f commit c743446a31fe5683544b78e9bf86dec371923b38 @bkeepers bkeepers committed Jan 12, 2010
Showing with 5 additions and 4 deletions.
  1. +2 −1 generators/delayed_job/templates/migration.rb
  2. +2 −2 lib/delayed/job.rb
  3. +1 −1 spec/job_spec.rb
@@ -11,7 +11,8 @@ def self.up
table.string :locked_by # Who is working on this object (if locked)
table.timestamps
end
-
+
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
end
def self.down
View
@@ -13,8 +13,8 @@ class Job < ActiveRecord::Base
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]}
}
- named_scope :by_priority, :order => 'priority DESC, run_at ASC'
-
+ named_scope :by_priority, :order => 'priority ASC, run_at ASC'
+
ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
# When a worker is exiting, make sure we don't have any locked jobs.
View
@@ -183,7 +183,7 @@
jobs = Delayed::Job.find_available('worker', 10)
ordered = true
jobs[1..-1].each_index{ |i|
- if (jobs[i].priority < jobs[i+1].priority)
+ if (jobs[i].priority > jobs[i+1].priority)
ordered = false
break
end

0 comments on commit c743446

Please sign in to comment.