perform_later 1.0.6 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,12 +3,7 @@ module PerformLater
3
3
  def self.get_digest(klass, method, *args)
4
4
  args = args.flatten
5
5
  payload = {:class => klass, :method => method.to_s, :args => args}.to_s
6
-
7
- puts payload
8
6
  digest = Digest::MD5.hexdigest(payload)
9
-
10
-
11
- puts "Digest is: #{digest}"
12
7
  digest
13
8
  end
14
9
  end
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -26,12 +26,31 @@ module Resque::Plugins::Later::Method
26
26
 
27
27
  def perform_later(queue, method, *args)
28
28
  ActiveSupport::Deprecation.warn("perform_later will be deprecated in future versions, please use the later method on your models")
29
+ args = PerformLater::ArgsParser.args_to_resque(args)
30
+ worker = PerformLater::Workers::ActiveRecord::Worker
31
+
32
+ enqueue_in_resque_or_send(worker, queue, method, args)
33
+ end
34
+
35
+ def perform_later!(queue, method, *args)
36
+ ActiveSupport::Deprecation.warn("perform_later! will be deprecated in future versions, please use the later method on your models")
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
29
41
 
30
- if PerformLater.config.enabled?
31
- args = PerformLater::ArgsParser.args_to_resque(args)
32
- Resque::Job.create(queue, PerformLater::Workers::ActiveRecord::Worker, self.class.name, self.id, method, *args)
33
- else
34
- self.send(method, args)
35
- end
42
+ return "AR EXISTS!" unless Resque.redis.get(digest).blank?
43
+ Resque.redis.set(digest, 'EXISTS')
44
+
45
+ enqueue_in_resque_or_send(worker, queue, method, args)
36
46
  end
47
+
48
+ private
49
+ def enqueue_in_resque_or_send(worker, queue, method, args)
50
+ if PerformLater.config.enabled?
51
+ Resque::Job.create(queue, worker, self.class.name, self.id, method, *args)
52
+ else
53
+ self.send(method, args)
54
+ end
55
+ end
37
56
  end
@@ -9,7 +9,7 @@ describe PerformLater::PayloadHelper do
9
9
  user = User.create
10
10
 
11
11
  digest = Digest::MD5.hexdigest({ :class => "DummyClass",
12
- :method => :some_method,
12
+ :method => :some_method.to_s,
13
13
  :args => ["AR:User:#{user.id}"]
14
14
  }.to_s)
15
15
 
@@ -18,6 +18,4 @@ describe PerformLater::PayloadHelper do
18
18
  subject.get_digest("DummyClass", :some_method, args).should == digest
19
19
  end
20
20
  end
21
-
22
-
23
21
  end
@@ -32,6 +32,16 @@ describe Resque::Plugins::Later::Method do
32
32
  user.lonely_long_running_method
33
33
  Resque.peek(:generic, 0, 20).length.should == 1
34
34
  end
35
+
36
+ it "should only add a single method to the queue, since the config is with a loner when using perform_later! method" do
37
+ user = User.create
38
+ user.perform_later!(:generic, :lonely_long_running_method)
39
+ user.perform_later!(:generic, :lonely_long_running_method)
40
+ user.perform_later!(:generic, :lonely_long_running_method)
41
+ user.perform_later!(:generic, :lonely_long_running_method)
42
+ user.perform_later!(:generic, :lonely_long_running_method)
43
+ Resque.peek(:generic, 0, 20).length.should == 1
44
+ end
35
45
  end
36
46
 
37
47
  context "disabled" do
@@ -48,5 +58,7 @@ describe Resque::Plugins::Later::Method do
48
58
  user.should respond_to(:now_long_running_method)
49
59
  end
50
60
 
61
+
62
+
51
63
 
52
64
  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.0.6
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: