Permalink
Browse files

Passing multiple arguments to `#enqueue` is deprecated

Pass a hash with :priority and :run_at.
  • Loading branch information...
1 parent 8c5dff6 commit 03c8070a7ac5ac5f683c725ab1ba8db7cbac6272 @bkeepers bkeepers committed Nov 24, 2010
Showing with 22 additions and 18 deletions.
  1. +8 −8 lib/delayed/backend/base.rb
  2. +14 −10 lib/delayed/backend/shared_spec.rb
@@ -10,14 +10,14 @@ module ClassMethods
def enqueue(*args)
options = {
:priority => Delayed::Worker.default_priority
- }
-
- if args.size == 1 && args.first.is_a?(Hash)
- options.merge!(args.first)
- else
- options[:payload_object] = args.shift
- options[:priority] = args.first || options[:priority]
- options[:run_at] = args[1]
+ }.merge!(args.extract_options!)
+
+ options[:payload_object] ||= args.shift
+
+ if args.size > 0
+ warn "[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at."
+ options[:priority] = args.first || options[:priority]
+ options[:run_at] = args[1]
end
unless options[:payload_object].respond_to?(:perform)
@@ -58,20 +58,24 @@ def create_job(opts = {})
described_class.count.should == 1
end
- it "should be able to set priority" do
- @job = described_class.enqueue SimpleJob.new, 5
- @job.priority.should == 5
+ it "should be able to set priority [DEPRECATED]" do
+ silence_warnings do
+ job = described_class.enqueue SimpleJob.new, 5
+ job.priority.should == 5
+ end
end
it "should use default priority when it is not set" do
@job = described_class.enqueue SimpleJob.new
@job.priority.should == 99
end
- it "should be able to set run_at" do
- later = described_class.db_time_now + 5.minutes
- @job = described_class.enqueue SimpleJob.new, 5, later
- @job.run_at.should be_within(1).of(later)
+ it "should be able to set run_at [DEPRECATED]" do
+ silence_warnings do
+ later = described_class.db_time_now + 5.minutes
+ @job = described_class.enqueue SimpleJob.new, 5, later
+ @job.run_at.should be_within(1).of(later)
+ end
end
it "should work with jobs in modules" do
@@ -205,7 +209,7 @@ def create_job(opts = {})
end
it "should fetch jobs ordered by priority" do
- 10.times { described_class.enqueue SimpleJob.new, rand(10) }
+ 10.times { described_class.enqueue SimpleJob.new, :priority => rand(10) }
jobs = []
10.times { jobs << described_class.reserve(worker) }
jobs.size.should == 10
@@ -217,14 +221,14 @@ def create_job(opts = {})
it "should only find jobs greater than or equal to min priority" do
min = 5
Delayed::Worker.min_priority = min
- 10.times {|i| described_class.enqueue SimpleJob.new, i }
+ 10.times {|i| described_class.enqueue SimpleJob.new, :priority => i }
5.times { described_class.reserve(worker).priority.should >= min }
end
it "should only find jobs less than or equal to max priority" do
max = 5
Delayed::Worker.max_priority = max
- 10.times {|i| described_class.enqueue SimpleJob.new, i }
+ 10.times {|i| described_class.enqueue SimpleJob.new, :priority => i }
5.times { described_class.reserve(worker).priority.should <= max }
end
end

0 comments on commit 03c8070

Please sign in to comment.