perform_later 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -29,12 +29,12 @@ If you are using bundler, simply add
|
|
29
29
|
|
30
30
|
|
31
31
|
## Configuration
|
32
|
-
|
33
|
-
|
34
|
-
Inside your `#{env}.rb` file (for example development.rb)
|
32
|
+
In an initializer, all you need to say is whether you want perform later to be enabled or not, typically, it will be something like this
|
35
33
|
|
36
34
|
```ruby
|
37
|
-
|
35
|
+
unless Rails.env.test?
|
36
|
+
PerformLater.config.later.enabled = true # this will default to false if unset
|
37
|
+
end
|
38
38
|
```
|
39
39
|
|
40
40
|
## Usage
|
data/lib/object_perform_later.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
module ObjectPerformLater
|
2
2
|
|
3
3
|
def perform_later(queue, method, *args)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
worker = PerformLater::Workers::Objects::Worker
|
5
|
+
perform_later_enqueue(worker, queue, method, args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def perform_later!(queue, method, *args)
|
9
|
+
worker = PerformLater::Workers::Objects::LoneWorker
|
10
|
+
perform_later_enqueue(worker, queue, method, args)
|
10
11
|
end
|
11
12
|
|
13
|
+
private
|
14
|
+
def perform_later_enqueue(worker, queue, method, args)
|
15
|
+
if PerformLater.config.enabled?
|
16
|
+
args = PerformLater::ArgsParser.args_to_resque(args)
|
17
|
+
Resque::Job.create(queue, worker, self.name, method, *args)
|
18
|
+
else
|
19
|
+
self.send(method, *args)
|
20
|
+
end
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
Object.send(:include, ObjectPerformLater)
|
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class DummyClass
|
4
|
+
def self.do_something_really_heavy
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
describe ObjectPerformLater do
|
4
10
|
it "should insert a task into resque when the config is enabled" do
|
5
11
|
Resque.redis = $redis
|
@@ -18,4 +24,17 @@ describe ObjectPerformLater do
|
|
18
24
|
|
19
25
|
Resque.peek(:generic, 0, 20).length.should == 0
|
20
26
|
end
|
27
|
+
|
28
|
+
it "should only add the method a single time to the queue" do
|
29
|
+
PerformLater.config.stub!(:enabled?).and_return(true)
|
30
|
+
|
31
|
+
DummyClass.perform_later!(:generic, :do_something_really_heavy)
|
32
|
+
DummyClass.perform_later!(:generic, :do_something_really_heavy)
|
33
|
+
DummyClass.perform_later!(:generic, :do_something_really_heavy)
|
34
|
+
DummyClass.perform_later!(:generic, :do_something_really_heavy)
|
35
|
+
|
36
|
+
Resque.peek(:generic, 0, 20).length.should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
|
21
40
|
end
|
@@ -30,7 +30,7 @@ describe Resque::Plugins::Later::Method do
|
|
30
30
|
user.lonely_long_running_method
|
31
31
|
user.lonely_long_running_method
|
32
32
|
user.lonely_long_running_method
|
33
|
-
Resque.peek(:generic, 0, 20).length.should == 1
|
33
|
+
Resque.peek(:generic, 0, 20).length.should == 1
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/spec/spec_helper.rb
CHANGED