perform_later 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/object_perform_later.rb +15 -15
- data/lib/perform_later/version.rb +1 -1
- data/lib/resque/plugins/later/method.rb +18 -17
- data/spec/lib/object_perform_later_spec.rb +39 -3
- metadata +2 -2
data/lib/object_perform_later.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
module ObjectPerformLater
|
2
2
|
def perform_later(queue, method, *args)
|
3
|
-
args
|
3
|
+
return self.send(method, *args) unless PerformLater.config.enabled?
|
4
4
|
|
5
5
|
worker = PerformLater::Workers::Objects::Worker
|
6
6
|
perform_later_enqueue(worker, queue, method, args)
|
7
7
|
end
|
8
8
|
|
9
9
|
def perform_later!(queue, method, *args)
|
10
|
-
args
|
11
|
-
|
12
|
-
|
13
|
-
return "EXISTS!" unless Resque.redis.get(digest).blank?
|
14
|
-
Resque.redis.set(digest, 'EXISTS')
|
10
|
+
return self.send(method, *args) unless PerformLater.config.enabled?
|
11
|
+
|
12
|
+
return "EXISTS!" if loner_exists(method, args)
|
15
13
|
|
16
14
|
worker = PerformLater::Workers::Objects::LoneWorker
|
17
15
|
perform_later_enqueue(worker, queue, method, args)
|
18
16
|
end
|
19
17
|
|
20
18
|
private
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
self.send(method, *args)
|
27
|
-
end
|
19
|
+
def loner_exists(method, args)
|
20
|
+
digest = PerformLater::PayloadHelper.get_digest(self.name, method, args)
|
21
|
+
return true unless Resque.redis.get(digest).blank?
|
22
|
+
Resque.redis.set(digest, 'EXISTS')
|
23
|
+
return false
|
28
24
|
end
|
29
|
-
end
|
30
25
|
|
31
|
-
|
26
|
+
def perform_later_enqueue(worker, queue, method, *args)
|
27
|
+
args = PerformLater::ArgsParser.args_to_resque(args)
|
28
|
+
Resque::Job.create(queue, worker, self.name, method, *args)
|
29
|
+
end
|
30
|
+
end
|
32
31
|
|
32
|
+
Object.send(:include, ObjectPerformLater)
|
@@ -25,33 +25,34 @@ module Resque::Plugins::Later::Method
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def perform_later(queue, method, *args)
|
28
|
-
|
29
|
-
|
30
|
-
worker = PerformLater::Workers::ActiveRecord::Worker
|
28
|
+
return self.send(method, *args) unless PerformLater.config.enabled?
|
29
|
+
|
31
30
|
|
31
|
+
worker = PerformLater::Workers::ActiveRecord::Worker
|
32
32
|
enqueue_in_resque_or_send(worker, queue, method, args)
|
33
33
|
end
|
34
34
|
|
35
35
|
def perform_later!(queue, method, *args)
|
36
|
-
|
37
|
-
|
38
|
-
args = PerformLater::ArgsParser.args_to_resque(args)
|
39
|
-
digest = PerformLater::PayloadHelper.get_digest(self.class.name, method, args)
|
40
|
-
worker = PerformLater::Workers::ActiveRecord::LoneWorker
|
36
|
+
return self.send(method, *args) unless PerformLater.config.enabled?
|
37
|
+
return "AR EXISTS!" if loner_exists(method, args)
|
41
38
|
|
42
|
-
|
43
|
-
Resque.redis.set(digest, 'EXISTS')
|
44
|
-
|
39
|
+
worker = PerformLater::Workers::ActiveRecord::LoneWorker
|
45
40
|
enqueue_in_resque_or_send(worker, queue, method, args)
|
46
41
|
end
|
47
42
|
|
48
43
|
private
|
44
|
+
def loner_exists(method, *args)
|
45
|
+
args = PerformLater::ArgsParser.args_to_resque(args)
|
46
|
+
digest = PerformLater::PayloadHelper.get_digest(self.class.name, method, args)
|
47
|
+
|
48
|
+
return true unless Resque.redis.get(digest).blank?
|
49
|
+
Resque.redis.set(digest, 'EXISTS')
|
50
|
+
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
49
54
|
def enqueue_in_resque_or_send(worker, queue, method, *args)
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
args = PerformLater::ArgsParser.args_from_resque(args)
|
54
|
-
self.send(method, *args)
|
55
|
-
end
|
55
|
+
args = PerformLater::ArgsParser.args_to_resque(args)
|
56
|
+
Resque::Job.create(queue, worker, self.class.name, self.id, method, *args)
|
56
57
|
end
|
57
58
|
end
|
@@ -8,6 +8,14 @@ class DummyClass
|
|
8
8
|
def self.do_something_with_string(value)
|
9
9
|
value
|
10
10
|
end
|
11
|
+
|
12
|
+
def self.do_something_with_user(user)
|
13
|
+
user
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.do_something_with_optional_hash(options = {})
|
17
|
+
options.blank?
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
describe ObjectPerformLater do
|
@@ -40,11 +48,39 @@ describe ObjectPerformLater do
|
|
40
48
|
Resque.peek(:generic, 0, 20).length.should == 1
|
41
49
|
end
|
42
50
|
|
43
|
-
describe :perform_later
|
51
|
+
describe :perform_later do
|
52
|
+
before(:each) do
|
53
|
+
PerformLater.config.stub!(:enabled?).and_return(false)
|
54
|
+
end
|
44
55
|
it "should pass the correct value (String)" do
|
56
|
+
DummyClass.perform_later(:generic, :do_something_with_string, "Avi Tzurel").should == "Avi Tzurel"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should pass the correct value (AR object)" do
|
60
|
+
user = User.create
|
61
|
+
DummyClass.perform_later(:generic, :do_something_with_user, user).should == user
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should pass the correct value (optional hash)" do
|
65
|
+
DummyClass.perform_later(:generic, :do_something_with_optional_hash).should == true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe :perform_later! do
|
70
|
+
before(:each) do
|
45
71
|
PerformLater.config.stub!(:enabled?).and_return(false)
|
46
|
-
|
47
|
-
|
72
|
+
end
|
73
|
+
it "should pass the correct value (String)" do
|
74
|
+
DummyClass.perform_later!(:generic, :do_something_with_string, "Avi Tzurel").should == "Avi Tzurel"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should pass the correct value (AR object)" do
|
78
|
+
user = User.create
|
79
|
+
DummyClass.perform_later!(:generic, :do_something_with_user, user).should == user
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should pass the correct value (optional hash)" do
|
83
|
+
DummyClass.perform_later!(:generic, :do_something_with_optional_hash).should == true
|
48
84
|
end
|
49
85
|
end
|
50
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perform_later
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|