resque_solo 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 90a8227c24d8deeb0fba498f2cadeacefe4b61ef
4
- data.tar.gz: fc44bea97f1765639572218b2249ec63cc9c6812
2
+ SHA256:
3
+ metadata.gz: 42df791660a5f4108b5832348ac269e28fbb6d112133083dd9cb4d69ca42e14a
4
+ data.tar.gz: 7e6736901c21f62746df7546feaa03fb859171ff059bf86f2471300a5473fadf
5
5
  SHA512:
6
- metadata.gz: 7b687be320d795f79cfc8d7f23f6973fca2b7e4b9a45126098adc4d37826ae5ac3670b886ddbdece53aa06328473de170e55dbae6aa094dcd7620acd5b24f33d
7
- data.tar.gz: 00465321bf6afaf929d15d8d6209c6cf98eee79af2f6d78b6814f5967bf8807b7ca30e0dadbc331b01ad2ae9a5c1fa389207a6ff36fa2c00b8cc1abb9d244a3c
6
+ metadata.gz: be28624643d67f66db4b6a24a162f141fc15435f9091f94e80a3e6b8849f05362e2ccd3a7f42c0226aade67818ce61031caabc3ad84fab7cf8b2e23db81af0cb
7
+ data.tar.gz: a295e26d4324f067d9798451fd466c07c0e0f9f29b5449af799b0b163f56d755823fea3432035c743a412b5718898dde490610045e96707b64f57505aadc0695
data/README.md CHANGED
@@ -10,7 +10,7 @@ ResqueSolo is a resque plugin to add unique jobs to resque.
10
10
 
11
11
  It is a re-write of [resque-loner](https://github.com/jayniz/resque-loner).
12
12
 
13
- It requires resque 1.25 and works with ruby 2.0 and later.
13
+ It requires resque 1.25 or greater and works with ruby 2.3 and later.
14
14
 
15
15
  It removes the dependency on `Resque::Helpers`, which is deprecated for resque 2.0.
16
16
 
@@ -19,7 +19,14 @@ It removes the dependency on `Resque::Helpers`, which is deprecated for resque 2
19
19
  Add the gem to your Gemfile:
20
20
 
21
21
  ```ruby
22
- gem 'resque_solo'
22
+ gem "resque_solo"
23
+ ```
24
+
25
+ To use with resque 2.0.0, which is unreleased as of 2018/7/24:
26
+
27
+ ```ruby
28
+ gem "resque", git: "https://github.com/resque/resque"
29
+ gem "resque_solo"
23
30
  ```
24
31
 
25
32
  ## Usage
@@ -39,11 +46,11 @@ If you attempt to queue a unique job multiple times, it is ignored:
39
46
 
40
47
  ```
41
48
  Resque.enqueue UpdateCat, 1
42
- => "OK"
49
+ => true
43
50
  Resque.enqueue UpdateCat, 1
44
- => "EXISTED"
51
+ => nil
45
52
  Resque.enqueue UpdateCat, 1
46
- => "EXISTED"
53
+ => nil
47
54
  Resque.size :cats
48
55
  => 1
49
56
  Resque.enqueued? UpdateCat, 1
@@ -64,3 +71,33 @@ The `lock_after_execution_period` setting can be used to delay when the unique j
64
71
  takes around 10 seconds, and you don't want to requeue another job until you are sure it is done,
65
72
  you could set `lock_after_execution_period = 20`. Or if you never want to run a long running
66
73
  job more than once per minute, set `lock_after_execution_period = 60`.
74
+
75
+ ```ruby
76
+ class UpdateCat
77
+ include Resque::Plugins::UniqueJob
78
+ @queue = :cats
79
+ @lock_after_execution_period = 20
80
+
81
+ def self.perform(cat_id)
82
+ # do something
83
+ end
84
+ end
85
+ ```
86
+
87
+ ## Development
88
+
89
+ Clone this repository, then:
90
+
91
+ Run tests with resque 1.x locally:
92
+
93
+ ```sh
94
+ bundle
95
+ bundle exec rake test
96
+ ```
97
+
98
+ Test supported versions of resque locally:
99
+
100
+ ```sh
101
+ appraisal install
102
+ appraisal rake test
103
+ ```
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Resque
2
4
  class Job
3
5
  class << self
@@ -1,5 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Resque
2
4
  class << self
5
+ # Override
6
+ # https://github.com/resque/resque/blob/master/lib/resque.rb
7
+ def enqueue_to(queue, klass, *args)
8
+ # Perform before_enqueue hooks. Don't perform enqueue if any hook returns false
9
+ before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook|
10
+ klass.send(hook, *args)
11
+ end
12
+ return nil if before_hooks.any? { |result| result == false }
13
+
14
+ result = Job.create(queue, klass, *args)
15
+ return nil if result == "EXISTED"
16
+
17
+ Plugin.after_enqueue_hooks(klass).each do |hook|
18
+ klass.send(hook, *args)
19
+ end
20
+
21
+ true
22
+ end
23
+
3
24
  def enqueued?(klass, *args)
4
25
  enqueued_in?(queue_from_class(klass), klass, *args)
5
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ResqueSolo
2
4
  class Queue
3
5
  class << self
@@ -60,8 +62,12 @@ module ResqueSolo
60
62
  end
61
63
 
62
64
  def cleanup(queue)
63
- keys = redis.keys("solo:queue:#{queue}:job:*")
64
- redis.del(*keys) if keys.any?
65
+ cursor = "0"
66
+ loop do
67
+ cursor, keys = redis.scan(cursor, match: "solo:queue:#{queue}:job:*")
68
+ redis.del(*keys) if keys.any?
69
+ break if cursor.to_i.zero?
70
+ end
65
71
  end
66
72
 
67
73
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "digest/md5"
2
4
 
3
5
  module Resque
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ResqueSolo
2
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
3
5
  end
data/lib/resque_solo.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "resque"
2
4
  require "resque_ext/job"
3
5
  require "resque_ext/resque"
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.25'
19
+ version: 1.25.0
20
20
  type: :runtime
21
21
  prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.25.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.25'
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +86,14 @@ dependencies:
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '11.2'
89
+ version: '12.0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '11.2'
96
+ version: '12.0'
83
97
  description: Resque plugin to add unique jobs
84
98
  email:
85
99
  - tee@neighborland.com
@@ -107,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: 2.0.0
124
+ version: 2.3.0
111
125
  required_rubygems_version: !ruby/object:Gem::Requirement
112
126
  requirements:
113
127
  - - ">="
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
129
  version: '0'
116
130
  requirements: []
117
131
  rubyforge_project:
118
- rubygems_version: 2.6.6
132
+ rubygems_version: 2.7.7
119
133
  signing_key:
120
134
  specification_version: 4
121
135
  summary: Resque plugin to add unique jobs