Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally exclude queues by worker #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/delayed/backend/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
ready_scope = ready_scope.where('priority >= ?', Worker.min_priority) if Worker.min_priority
ready_scope = ready_scope.where('priority <= ?', Worker.max_priority) if Worker.max_priority
ready_scope = ready_scope.where(:queue => Worker.queues) if Worker.queues.any?
ready_scope = ready_scope.where("queue NOT IN (?) OR queue IS NULL", Worker.excludes) if Worker.respond_to?(:excludes) && Worker.excludes.any?
ready_scope = ready_scope.by_priority

now = self.db_time_now
Expand Down
27 changes: 27 additions & 0 deletions spec/delayed/backend/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,33 @@
end
end

describe "process" do
it "reserves jobs from the correct queue" do
# clear any jobs sitting around
Delayed::Backend::ActiveRecord::Job.delete_all

job = Delayed::Backend::ActiveRecord::Job.enqueue :payload_object => SimpleJob.new, :queue => 'queue'
Delayed::Backend::ActiveRecord::Job.count.should == 1
Delayed::Worker.new(:queue => 'queue').work_off
Delayed::Backend::ActiveRecord::Job.count.should == 0
end

if Delayed::Worker.respond_to?(:excludes)
it "ignores excluded queues when reserving jobs" do
# clear any jobs sitting around
Delayed::Backend::ActiveRecord::Job.delete_all

job = Delayed::Backend::ActiveRecord::Job.enqueue :payload_object => SimpleJob.new, :queue => 'process'
excluded_job = Delayed::Backend::ActiveRecord::Job.enqueue :payload_object => SimpleJob.new, :queue => 'ignore'
Delayed::Worker.excludes << 'ignore'
Delayed::Worker.new.work_off

Delayed::Backend::ActiveRecord::Job.find(excluded_job.id).queue.should == 'ignore'
Delayed::Backend::ActiveRecord::Job.count.should == 1
end
end
end

if ::ActiveRecord::VERSION::MAJOR < 4 || defined?(::ActiveRecord::MassAssignmentSecurity)
context "ActiveRecord::Base.send(:attr_accessible, nil)" do
before do
Expand Down