Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate #send_later and #send_at in favor of new #delay method

  • Loading branch information...
commit 2f11ac26519d0a18f3af4c1cb05d79afd3300ff5 1 parent 49444b6
@bkeepers bkeepers authored
View
4 README.textile
@@ -68,14 +68,14 @@ Delayed::Worker.backend.auto_upgrade!
h2. Queuing Jobs
-Call @#send_later(method, params)@ on any object and it will be processed in the background.
+Call @.delay.method(params)@ on any object and it will be processed in the background.
<pre>
# without delayed_job
Notifier.deliver_signup(@user)
# with delayed_job
-Notifier.send_later :deliver_signup, @user
+Notifier.delay.deliver_signup @user
</pre>
If a method should always be run in the background, you can call @#handle_asynchronously@ after the method declaration:
View
2  benchmarks.rb
@@ -26,7 +26,7 @@
Delayed::Worker.backend = backend
n = 10000
- n.times { "foo".send_later :length }
+ n.times { "foo".delay.length }
x.report(backend.to_s) { Delayed::Worker.new(:quiet => true).work_off(n) }
end
View
12 lib/delayed/message_sending.rb
@@ -18,21 +18,23 @@ def delay(options = {})
end
def send_later(method, *args)
- Delayed::Job.enqueue Delayed::PerformableMethod.new(self, method.to_sym, args)
+ warn "[DEPRECATION] `object.send_later(:method)` is deprecated. Use `object.delay.method"
+ delay.__send__(method, *args)
end
def send_at(time, method, *args)
- Delayed::Job.enqueue(Delayed::PerformableMethod.new(self, method.to_sym, args), 0, time)
+ warn "[DEPRECATION] `object.send_at(time, :method)` is deprecated. Use `object.delay(:run_at => time).method"
+ delay(:run_at => time).__send__(method, *args)
end
module ClassMethods
def handle_asynchronously(method)
aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
- with_method, without_method = "#{aliased_method}_with_send_later#{punctuation}", "#{aliased_method}_without_send_later#{punctuation}"
+ with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}"
define_method(with_method) do |*args|
- send_later(without_method, *args)
+ delay.__send__(without_method, *args)
end
- alias_method_chain method, :send_later
+ alias_method_chain method, :delay
end
end
end
View
6 spec/backend/mongo_mapper_job_spec.rb
@@ -41,14 +41,14 @@ def tell
it "should ignore not found errors because they are permanent" do
story = MongoStory.create :text => 'Once upon a time...'
- job = story.send_later(:tell)
+ job = story.delay.tell
story.destroy
lambda { job.invoke_job }.should_not raise_error
end
it "should store the object as string" do
story = MongoStory.create :text => 'Once upon a time...'
- job = story.send_later(:tell)
+ job = story.delay.tell
job.payload_object.class.should == Delayed::PerformableMethod
job.payload_object.object.should == story
@@ -59,7 +59,7 @@ def tell
it "should store arguments as string" do
story = MongoStory.create :text => 'Once upon a time...'
- job = MongoStoryReader.new.send_later(:read, story)
+ job = MongoStoryReader.new.delay.read(story)
job.payload_object.class.should == Delayed::PerformableMethod
job.payload_object.method.should == :read
job.payload_object.args.should == [story]
View
4 spec/backend/shared_backend_spec.rb
@@ -173,12 +173,12 @@ def create_job(opts = {})
end
it "should be the method that will be called if its a performable method object" do
- @job = Story.send_later(:create)
+ @job = Story.delay.create
@job.name.should == "Story.create"
end
it "should be the instance method that will be called if its a performable method object" do
- @job = Story.create(:text => "...").send_later(:save)
+ @job = Story.create(:text => "...").delay.save
@job.name.should == 'Story#save'
end
end
View
46 spec/delayed_method_spec.rb
@@ -1,25 +1,9 @@
require 'spec_helper'
-describe 'random ruby objects' do
+describe Object do
before { Delayed::Job.delete_all }
- it "should respond_to :send_later method" do
- Object.new.respond_to?(:send_later)
- end
-
- it "should raise a ArgumentError if send_later is called but the target method doesn't exist" do
- lambda { Object.new.send_later(:method_that_deos_not_exist) }.should raise_error(NoMethodError)
- end
-
- it "should add a new entry to the job table when send_later is called on it" do
- lambda { Object.new.send_later(:to_s) }.should change { Delayed::Job.count }.by(1)
- end
-
- it "should add a new entry to the job table when send_later is called on the class" do
- lambda { Object.send_later(:to_s) }.should change { Delayed::Job.count }.by(1)
- end
-
- it "should call send later on methods which are wrapped with handle_asynchronously" do
+ it "should call #delay on methods which are wrapped with handle_asynchronously" do
story = Story.create :text => 'Once upon...'
Delayed::Job.count.should == 0
@@ -29,33 +13,11 @@
Delayed::Job.count.should == 1
job = Delayed::Job.first
job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.method.should == :whatever_without_send_later
+ job.payload_object.method.should == :whatever_without_delay
job.payload_object.args.should == [1, 5]
job.payload_object.perform.should == 'Once upon...'
end
- context "send_at" do
- it "should queue a new job" do
- lambda do
- "string".send_at(1.hour.from_now, :length)
- end.should change { Delayed::Job.count }.by(1)
- end
-
- it "should schedule the job in the future" do
- time = 1.hour.from_now.utc.to_time
- job = "string".send_at(time, :length)
- job.run_at.to_i.should == time.to_i
- end
-
- it "should store payload as PerformableMethod" do
- job = "string".send_at(1.hour.from_now, :count, 'r')
- job.payload_object.class.should == Delayed::PerformableMethod
- job.payload_object.method.should == :count
- job.payload_object.args.should == ['r']
- job.payload_object.perform.should == 1
- end
- end
-
context "delay" do
it "should raise a ArgumentError if target method doesn't exist" do
lambda { Object.new.delay.method_that_does_not_exist }.should raise_error(NoMethodError)
@@ -80,7 +42,5 @@
job = 3.delay.+(5)
job.payload_object.args.should == [5]
end
-
end
-
end
View
2  spec/story_spec.rb
@@ -11,7 +11,7 @@
end
it "should not return its result if it storytelling is delayed" do
- @story.send_later(:tell).should_not == 'Once upon a time...'
+ @story.delay.tell.should_not == 'Once upon a time...'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.