perform_later 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  module ObjectPerformLater
2
-
3
2
  def perform_later(queue, method, *args)
4
3
  args = PerformLater::ArgsParser.args_to_resque(args)
5
4
 
@@ -9,8 +8,8 @@ module ObjectPerformLater
9
8
 
10
9
  def perform_later!(queue, method, *args)
11
10
  args = PerformLater::ArgsParser.args_to_resque(args)
12
- digest = Digest::MD5.hexdigest({:class => self.name, :args => args}.to_s)
13
-
11
+
12
+ digest = PerformLater::PayloadHelper.get_digest(self.name, method, args)
14
13
  return "EXISTS!" unless Resque.redis.get(digest).blank?
15
14
  Resque.redis.set(digest, 'EXISTS')
16
15
 
@@ -21,9 +20,9 @@ module ObjectPerformLater
21
20
  private
22
21
  def perform_later_enqueue(worker, queue, method, args)
23
22
  if PerformLater.config.enabled?
24
- Resque::Job.create(queue, worker, self.name, method, *args)
23
+ Resque::Job.create(queue, worker, self.name, method, args)
25
24
  else
26
- self.send(method, *args)
25
+ self.send(method, args)
27
26
  end
28
27
  end
29
28
  end
@@ -8,7 +8,7 @@ module PerformLater
8
8
  YAML_STRING_FORMAT = /\A---/
9
9
 
10
10
  def self.args_to_resque(*args)
11
- args = args.map { |o|
11
+ args = args.flatten.map { |o|
12
12
  case o
13
13
  when ActiveRecord::Base
14
14
  "AR:#{o.class.name}:#{o.id}"
@@ -23,7 +23,7 @@ module PerformLater
23
23
  end
24
24
 
25
25
  def self.args_from_resque(*args)
26
- args = args.map { |o|
26
+ args = args.flatten.map { |o|
27
27
  if o
28
28
  case o
29
29
  when CLASS_STRING_FORMAT then $1.constantize
@@ -0,0 +1,15 @@
1
+ module PerformLater
2
+ class PayloadHelper
3
+ def self.get_digest(klass, method, *args)
4
+ args = args.flatten
5
+ payload = {:class => klass, :method => method.to_s, :args => args}.to_s
6
+
7
+ puts payload
8
+ digest = Digest::MD5.hexdigest(payload)
9
+
10
+
11
+ puts "Digest is: #{digest}"
12
+ digest
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -2,9 +2,9 @@ module PerformLater
2
2
  module Workers
3
3
  module ActiveRecord
4
4
  class LoneWorker
5
- def self.perform(klass, id, method, *args)
5
+ def self.perform(klass, id, method, args)
6
6
  # Remove the loner flag from redis
7
- digest = Digest::MD5.hexdigest({:class => klass, :args => args}.to_s)
7
+ digest = PerformLater::PayloadHelper.get_digest(klass, method_name, args)
8
8
  Resque.redis.del(digest)
9
9
 
10
10
  args = PerformLater::ArgsParser.args_from_resque(args)
@@ -16,4 +16,4 @@ module PerformLater
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -3,8 +3,8 @@ module PerformLater
3
3
  module Objects
4
4
  class LoneWorker
5
5
  def self.perform(klass_name, method, *args)
6
- # Remove the loner flag from redis
7
- digest = Digest::MD5.hexdigest({:class => klass, :args => args}.to_s)
6
+ #
7
+ digest = PerformLater::PayloadHelper.get_digest(klass_name, method, args)
8
8
  Resque.redis.del(digest)
9
9
 
10
10
  args = PerformLater::ArgsParser.args_from_resque(args)
data/lib/perform_later.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'active_support/dependencies'
2
2
  require 'perform_later/version'
3
3
  require 'perform_later/config'
4
- require 'resque'
4
+ require 'perform_later/payload_helper'
5
5
  require 'perform_later/args_parser'
6
+ require 'resque'
6
7
  require 'active_record'
7
8
  require 'resque_mailer_patch'
8
9
  require 'object_perform_later'
@@ -12,10 +12,10 @@ module Resque::Plugins::Later::Method
12
12
  klass = PerformLater::Workers::ActiveRecord::Worker
13
13
  klass = PerformLater::Workers::ActiveRecord::LoneWorker if loner
14
14
  args = PerformLater::ArgsParser.args_to_resque(args)
15
- digest = Digest::MD5.hexdigest({:class => klass, :args => args}.to_s)
15
+ digest = PerformLater::PayloadHelper.get_digest(klass, method_name, args)
16
16
 
17
17
  if loner
18
- return "EXISTS!" unless Resque.redis.get(digest).blank?
18
+ return "AR EXISTS!" unless Resque.redis.get(digest).blank?
19
19
  Resque.redis.set(digest, 'EXISTS')
20
20
  end
21
21
 
@@ -31,7 +31,7 @@ module Resque::Plugins::Later::Method
31
31
  args = PerformLater::ArgsParser.args_to_resque(args)
32
32
  Resque::Job.create(queue, PerformLater::Workers::ActiveRecord::Worker, self.class.name, self.id, method, *args)
33
33
  else
34
- self.send(method, *args)
34
+ self.send(method, args)
35
35
  end
36
36
  end
37
37
  end
@@ -13,12 +13,12 @@ describe PerformLater::ArgsParser do
13
13
  end
14
14
 
15
15
  it "should convert a hash into YAML string so that Resque will be able to JSON convert it" do
16
- hash = {name: "something", other: "something else"}
16
+ hash = { name: "something", other: "something else" }
17
17
  subject.args_to_resque(hash)[0].class.name.should == "String"
18
18
  end
19
19
 
20
20
  it "should be able to load a yaml from the string and translate it into the same hash again" do
21
- hash = {name: "something", other: "something else"}
21
+ hash = { name: "something", other: "something else" }
22
22
  yaml = subject.args_to_resque(hash)[0]
23
23
 
24
24
  loaded_yaml = YAML.load(yaml)
@@ -35,7 +35,7 @@ describe PerformLater::ArgsParser do
35
35
 
36
36
  context "args from resque" do
37
37
  it "should give me a hash back when I pass a yaml representation of it" do
38
- hash = {name: "something", other: "something else"}
38
+ hash = { name: "something", other: "something else" }
39
39
  yaml = hash.to_yaml
40
40
 
41
41
  args = subject.args_from_resque(yaml)
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe PerformLater::PayloadHelper do
5
+ subject { PerformLater::PayloadHelper }
6
+
7
+ describe :get_digest do
8
+ it "should o something" do
9
+ user = User.create
10
+
11
+ digest = Digest::MD5.hexdigest({ :class => "DummyClass",
12
+ :method => :some_method,
13
+ :args => ["AR:User:#{user.id}"]
14
+ }.to_s)
15
+
16
+ args = PerformLater::ArgsParser.args_to_resque(user)
17
+ puts args
18
+ subject.get_digest("DummyClass", :some_method, args).should == digest
19
+ end
20
+ end
21
+
22
+
23
+ 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.4
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -190,6 +190,7 @@ files:
190
190
  - lib/perform_later.rb
191
191
  - lib/perform_later/args_parser.rb
192
192
  - lib/perform_later/config.rb
193
+ - lib/perform_later/payload_helper.rb
193
194
  - lib/perform_later/railtie.rb
194
195
  - lib/perform_later/version.rb
195
196
  - lib/perform_later/workers/active_record/lone_worker.rb
@@ -203,6 +204,7 @@ files:
203
204
  - spec/lib/object_perform_later_spec.rb
204
205
  - spec/lib/perform_later/args_parser_spec.rb
205
206
  - spec/lib/perform_later/config_spec.rb
207
+ - spec/lib/perform_later/payload_helper_spec.rb
206
208
  - spec/lib/perform_later_spec.rb
207
209
  - spec/lib/resque/plugins/later/method_spec.rb
208
210
  - spec/spec_helper.rb
@@ -239,6 +241,7 @@ test_files:
239
241
  - spec/lib/object_perform_later_spec.rb
240
242
  - spec/lib/perform_later/args_parser_spec.rb
241
243
  - spec/lib/perform_later/config_spec.rb
244
+ - spec/lib/perform_later/payload_helper_spec.rb
242
245
  - spec/lib/perform_later_spec.rb
243
246
  - spec/lib/resque/plugins/later/method_spec.rb
244
247
  - spec/spec_helper.rb