perform_later 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -96,6 +96,14 @@ If you want object methods to be queued, you will have to use the `perform_later
96
96
 
97
97
  SomeClass.perform_later(:queue_name, :some_heavy_lifting_method)
98
98
  SomeClass.perform_later(:queue_name, :some_more_heavy_lifting, user_id)
99
+
100
+
101
+ ```
102
+
103
+ If you want the method to be a loner (only a single instance in the queue), you will need to use the `perform_later!` method.
104
+
105
+ ```ruby
106
+ SomeClass.perform_later!(:queue_name, :some_more_heavy_lifting, user_id)
99
107
  ```
100
108
 
101
109
  ## The params parser
@@ -1,11 +1,19 @@
1
1
  module ObjectPerformLater
2
2
 
3
3
  def perform_later(queue, method, *args)
4
+ args = PerformLater::ArgsParser.args_to_resque(args)
5
+
4
6
  worker = PerformLater::Workers::Objects::Worker
5
7
  perform_later_enqueue(worker, queue, method, args)
6
8
  end
7
9
 
8
10
  def perform_later!(queue, method, *args)
11
+ args = PerformLater::ArgsParser.args_to_resque(args)
12
+ digest = Digest::MD5.hexdigest({:class => self.name, :args => args}.to_s)
13
+
14
+ return "EXISTS!" unless Resque.redis.get(digest).blank?
15
+ Resque.redis.set(digest, 'EXISTS')
16
+
9
17
  worker = PerformLater::Workers::Objects::LoneWorker
10
18
  perform_later_enqueue(worker, queue, method, args)
11
19
  end
@@ -13,7 +21,6 @@ module ObjectPerformLater
13
21
  private
14
22
  def perform_later_enqueue(worker, queue, method, args)
15
23
  if PerformLater.config.enabled?
16
- args = PerformLater::ArgsParser.args_to_resque(args)
17
24
  Resque::Job.create(queue, worker, self.name, method, *args)
18
25
  else
19
26
  self.send(method, *args)
@@ -1,3 +1,3 @@
1
1
  module PerformLater
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -2,9 +2,11 @@ module PerformLater
2
2
  module Workers
3
3
  module ActiveRecord
4
4
  class LoneWorker
5
- include Resque::Plugins::UniqueJob
6
-
7
5
  def self.perform(klass, id, method, *args)
6
+ # Remove the loner flag from redis
7
+ digest = Digest::MD5.hexdigest({:class => klass, :args => args}.to_s)
8
+ Resque.redis.del(digest)
9
+
8
10
  args = PerformLater::ArgsParser.args_from_resque(args)
9
11
  runner_klass = eval(klass)
10
12
 
@@ -2,9 +2,11 @@ module PerformLater
2
2
  module Workers
3
3
  module Objects
4
4
  class LoneWorker
5
- include Resque::Plugins::UniqueJob
6
-
7
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)
8
+ Resque.redis.del(digest)
9
+
8
10
  args = PerformLater::ArgsParser.args_from_resque(args)
9
11
  klass_name.constantize.send(method, *args)
10
12
  end
@@ -11,9 +11,12 @@ module Resque::Plugins::Later::Method
11
11
  queue = opts.fetch(:queue, :generic)
12
12
  klass = PerformLater::Workers::ActiveRecord::Worker
13
13
  klass = PerformLater::Workers::ActiveRecord::LoneWorker if loner
14
+ args = PerformLater::ArgsParser.args_to_resque(args)
15
+ digest = Digest::MD5.hexdigest({:class => klass, :args => args}.to_s)
14
16
 
15
17
  if loner
16
- return "QUEUED!" if Resque.enqueued_in? queue, klass, args
18
+ return "EXISTS!" unless Resque.redis.get(digest).blank?
19
+ Resque.redis.set(digest, 'EXISTS')
17
20
  end
18
21
 
19
22
  Resque::Job.create(queue, klass, send(:class).name, send(:id), "now_#{method_name}", args)
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  s.add_dependency 'rails', '~> 3.0'
23
23
  s.add_dependency 'resque'
24
- s.add_dependency 'resque-loner'
25
24
  s.add_dependency 'redis'
26
25
 
27
26
 
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.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: resque-loner
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: redis
64
48
  requirement: !ruby/object:Gem::Requirement