sidekiq-unique-jobs 3.0.12 → 3.0.13
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq-unique-jobs might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -6
- data/Appraisals +11 -8
- data/CHANGELOG.md +6 -0
- data/README.md +22 -0
- data/gemfiles/sidekiq_2.17.gemfile +1 -1
- data/gemfiles/sidekiq_3.0.gemfile +2 -2
- data/gemfiles/sidekiq_3.1.gemfile +9 -0
- data/gemfiles/sidekiq_3.2.gemfile +9 -0
- data/gemfiles/sidekiq_3.3.gemfile +9 -0
- data/gemfiles/sidekiq_develop.gemfile +2 -2
- data/lib/sidekiq-unique-jobs.rb +2 -0
- data/lib/sidekiq_unique_jobs/config.rb +6 -2
- data/lib/sidekiq_unique_jobs/{testing.rb → inline_testing.rb} +0 -0
- data/lib/sidekiq_unique_jobs/middleware/client/strategies/unique.rb +15 -5
- data/lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb +5 -1
- data/lib/sidekiq_unique_jobs/sidekiq_test_overrides.rb +101 -0
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/spec/lib/client_spec.rb +20 -0
- data/spec/lib/sidekiq_testing_enabled_spec.rb +91 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/another_unique_worker.rb +13 -0
- data/spec/support/my_worker.rb +2 -2
- data/spec/support/unique_worker.rb +2 -2
- metadata +8 -4
- data/spec/lib/.sidekiq_testing_enabled_spec.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b074cf18e3e7d0878e69527a8716e0c962cf9279
|
4
|
+
data.tar.gz: b960227a096e842d45446eb2e44d916b638451a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaaf71ae3c669a2cb77390e1d4c4a9fd12ef0cb1909f187cc9435ff858b6c2967a2e5f64f15c2b129f2776b9c1dd112bc1d44bdb0da114cdcd38aa0a8adf7b50
|
7
|
+
data.tar.gz: 985a07f514bbc295c1ef2191eacde190246c0d6a7368f1db82046e77a487a7bc1207edfda5c485d4775a9d9d0592ef1e97c937384ff8979c069a732179e10e27
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -2,17 +2,16 @@ language: ruby
|
|
2
2
|
services:
|
3
3
|
- redis-server
|
4
4
|
rvm:
|
5
|
-
- 1.9.3
|
6
5
|
- jruby-19mode
|
7
|
-
-
|
6
|
+
- rbx2
|
8
7
|
- 2.0.0
|
9
8
|
- 2.1.2
|
10
9
|
- 2.2.2
|
11
10
|
gemfile:
|
12
|
-
- gemfiles/sidekiq_2.15.gemfile
|
13
|
-
- gemfiles/sidekiq_2.16.gemfile
|
14
|
-
- gemfiles/sidekiq_2.17.gemfile
|
15
11
|
- gemfiles/sidekiq_3.0.gemfile
|
12
|
+
- gemfiles/sidekiq_3.1.gemfile
|
13
|
+
- gemfiles/sidekiq_3.2.gemfile
|
14
|
+
- gemfiles/sidekiq_3.3.gemfile
|
16
15
|
- gemfiles/sidekiq_develop.gemfile
|
17
16
|
branches:
|
18
17
|
only:
|
@@ -23,4 +22,4 @@ notifications:
|
|
23
22
|
- mikael@zoolutions.se
|
24
23
|
matrix:
|
25
24
|
allow_failures:
|
26
|
-
- rvm:
|
25
|
+
- rvm: rbx2
|
data/Appraisals
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
appraise "sidekiq-develop" do
|
2
2
|
gem 'sidekiq', github: 'mperham/sidekiq'
|
3
|
-
gem 'sidekiq', '3.0', :platform => :mri_19
|
4
3
|
end
|
5
4
|
|
6
5
|
appraise "sidekiq-2.17" do
|
7
|
-
gem 'sidekiq', '2.17'
|
6
|
+
gem 'sidekiq', '~> 2.17.0'
|
8
7
|
end
|
9
8
|
|
10
|
-
appraise "sidekiq-
|
11
|
-
gem "sidekiq", '
|
9
|
+
appraise "sidekiq-3.0" do
|
10
|
+
gem "sidekiq", '~> 3.0.0'
|
12
11
|
end
|
13
12
|
|
14
|
-
appraise "sidekiq-
|
15
|
-
gem "sidekiq", '
|
13
|
+
appraise "sidekiq-3.1" do
|
14
|
+
gem "sidekiq", '~> 3.1.0'
|
16
15
|
end
|
17
16
|
|
18
|
-
appraise "sidekiq-3.
|
19
|
-
gem "sidekiq", '3.0'
|
17
|
+
appraise "sidekiq-3.2" do
|
18
|
+
gem "sidekiq", '~> 3.2.0'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "sidekiq-3.3" do
|
22
|
+
gem "sidekiq", '~> 3.3.0'
|
20
23
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## v3.0.13
|
2
|
+
- Improved testing capabilities (testing uniqueness should not work better)
|
3
|
+
- Configurable logging of duplicate payloads
|
4
|
+
- Now requires `sidekiq_unique_ext` and `sidekiq/api` by default
|
5
|
+
- Drop support for MRI 1.9 and sidekiq 2
|
6
|
+
|
1
7
|
## v3.0.11
|
2
8
|
- Ensure threadsafety (thanks to adstage-david)
|
3
9
|
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
The missing unique jobs for sidekiq
|
4
4
|
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
See https://github.com/mperham/sidekiq#requirements for what is required. Starting from 3.0.13 only sidekiq 3 is supported and support for MRI 1.9 is dropped (it might work but won't be worked on)
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -92,6 +96,21 @@ class UniqueJobWithFilterMethod
|
|
92
96
|
end
|
93
97
|
```
|
94
98
|
|
99
|
+
### Logging
|
100
|
+
|
101
|
+
To see logging in sidekiq when duplicate payload has been filtered out you can enable on a per worker basis using the sidekiq options. The default value is false
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class UniqueJobWithFilterMethod
|
105
|
+
include Sidekiq::Worker
|
106
|
+
sidekiq_options unique: true,
|
107
|
+
log_duplicate_payload: true
|
108
|
+
|
109
|
+
...
|
110
|
+
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
95
114
|
### Testing
|
96
115
|
|
97
116
|
SidekiqUniqueJobs uses mock_redis for inline testing. Due to complaints about having that as a runtime dependency it was made a development dependency so if you are relying on inline testing you will have to add `gem 'mock_redis'` to your Gemfile.
|
@@ -112,3 +131,6 @@ SidekiqUniqueJobs uses mock_redis for inline testing. Due to complaints about ha
|
|
112
131
|
- https://github.com/eduardosasso
|
113
132
|
- https://github.com/KensoDev
|
114
133
|
- https://github.com/adstage-david
|
134
|
+
- https://github.com/jprincipe
|
135
|
+
- https://github.com/crberube
|
136
|
+
- https://github.com/simonoff
|
data/lib/sidekiq-unique-jobs.rb
CHANGED
@@ -4,6 +4,8 @@ require 'sidekiq_unique_jobs/middleware'
|
|
4
4
|
require 'sidekiq_unique_jobs/version'
|
5
5
|
require 'sidekiq_unique_jobs/config'
|
6
6
|
require 'sidekiq_unique_jobs/payload_helper'
|
7
|
+
require 'sidekiq_unique_jobs/sidekiq_unique_ext'
|
8
|
+
|
7
9
|
require 'ostruct'
|
8
10
|
|
9
11
|
module SidekiqUniqueJobs
|
@@ -31,14 +31,18 @@ module SidekiqUniqueJobs
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def inline_testing_enabled?
|
34
|
-
if
|
35
|
-
require 'sidekiq_unique_jobs/
|
34
|
+
if testing_enabled? && Sidekiq::Testing.inline?
|
35
|
+
require 'sidekiq_unique_jobs/inline_testing'
|
36
36
|
return true
|
37
37
|
end
|
38
38
|
|
39
39
|
false
|
40
40
|
end
|
41
41
|
|
42
|
+
def testing_enabled?
|
43
|
+
Sidekiq.const_defined?('Testing') && Sidekiq::Testing.enabled?
|
44
|
+
end
|
45
|
+
|
42
46
|
def unique_args_enabled?
|
43
47
|
config.unique_args_enabled
|
44
48
|
end
|
File without changes
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'digest'
|
2
2
|
require 'sidekiq_unique_jobs/connectors'
|
3
3
|
|
4
|
+
REQUIRE_FILES = lambda do
|
5
|
+
if SidekiqUniqueJobs.config.testing_enabled? && Sidekiq::Testing.fake?
|
6
|
+
require 'sidekiq_unique_jobs/sidekiq_test_overrides'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
module SidekiqUniqueJobs
|
5
11
|
module Middleware
|
6
12
|
module Client
|
@@ -10,21 +16,25 @@ module SidekiqUniqueJobs
|
|
10
16
|
true
|
11
17
|
end
|
12
18
|
|
13
|
-
def self.review(worker_class, item, queue, redis_pool = nil)
|
14
|
-
new(worker_class, item, queue, redis_pool).review { yield }
|
19
|
+
def self.review(worker_class, item, queue, redis_pool = nil, log_duplicate_payload = false)
|
20
|
+
new(worker_class, item, queue, redis_pool, log_duplicate_payload).review { yield }
|
15
21
|
end
|
16
22
|
|
17
|
-
def initialize(worker_class, item, queue, redis_pool = nil)
|
23
|
+
def initialize(worker_class, item, queue, redis_pool = nil, log_duplicate_payload = false)
|
18
24
|
@worker_class = SidekiqUniqueJobs.worker_class_constantize(worker_class)
|
19
25
|
@item = item
|
20
26
|
@queue = queue
|
21
27
|
@redis_pool = redis_pool
|
28
|
+
@log_duplicate_payload = log_duplicate_payload
|
29
|
+
REQUIRE_FILES.call
|
22
30
|
end
|
23
31
|
|
24
32
|
def review
|
25
33
|
item['unique_hash'] = payload_hash
|
26
34
|
unless unique_for_connection?
|
27
|
-
|
35
|
+
if @log_duplicate_payload
|
36
|
+
Sidekiq.logger.warn "payload is not unique #{item}"
|
37
|
+
end
|
28
38
|
return
|
29
39
|
end
|
30
40
|
yield
|
@@ -32,7 +42,7 @@ module SidekiqUniqueJobs
|
|
32
42
|
|
33
43
|
private
|
34
44
|
|
35
|
-
attr_reader :item, :worker_class, :redis_pool, :queue
|
45
|
+
attr_reader :item, :worker_class, :redis_pool, :queue, :log_duplicate_payload
|
36
46
|
|
37
47
|
# rubocop:disable MethodLength
|
38
48
|
def unique_for_connection?
|
@@ -18,7 +18,7 @@ module SidekiqUniqueJobs
|
|
18
18
|
@redis_pool = redis_pool
|
19
19
|
|
20
20
|
if unique_enabled?
|
21
|
-
strategy.review(worker_class, item, queue, redis_pool) { yield }
|
21
|
+
strategy.review(worker_class, item, queue, redis_pool, log_duplicate_payload?) { yield }
|
22
22
|
else
|
23
23
|
yield
|
24
24
|
end
|
@@ -30,6 +30,10 @@ module SidekiqUniqueJobs
|
|
30
30
|
worker_class.get_sidekiq_options['unique'] || item['unique']
|
31
31
|
end
|
32
32
|
|
33
|
+
def log_duplicate_payload?
|
34
|
+
worker_class.get_sidekiq_options['log_duplicate_payload'] || item['log_duplicate_payload']
|
35
|
+
end
|
36
|
+
|
33
37
|
def strategy
|
34
38
|
STRATEGIES.detect(&:elegible?)
|
35
39
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'sidekiq/testing'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module Worker
|
5
|
+
module ClassMethods
|
6
|
+
module Overrides
|
7
|
+
def self.included(base)
|
8
|
+
override_methods(base) unless base.method_defined?(:execute_job)
|
9
|
+
|
10
|
+
base.class_eval do
|
11
|
+
alias_method :execute_job_orig, :execute_job
|
12
|
+
alias_method :execute_job, :execute_job_ext
|
13
|
+
|
14
|
+
alias_method :clear_orig, :clear
|
15
|
+
alias_method :clear, :clear_ext
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute_job_ext(worker, args)
|
20
|
+
execute_job_orig(worker, args)
|
21
|
+
payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload(
|
22
|
+
worker.class.name,
|
23
|
+
get_sidekiq_options['queue'],
|
24
|
+
args
|
25
|
+
)
|
26
|
+
Sidekiq.redis { |conn| conn.del(payload_hash) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear_ext
|
30
|
+
payload_hashes = jobs.map { |job| job['unique_hash'] }
|
31
|
+
clear_orig
|
32
|
+
return if payload_hashes.empty?
|
33
|
+
|
34
|
+
Sidekiq.redis { |conn| conn.del(*payload_hashes) }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Disable rubocop because methods are lifted directly out of Sidekiq
|
38
|
+
# rubocop:disable all
|
39
|
+
def override_methods(base)
|
40
|
+
base.class_eval do
|
41
|
+
define_method(:drain) do
|
42
|
+
while job = jobs.shift do
|
43
|
+
worker = new
|
44
|
+
worker.jid = job['jid']
|
45
|
+
execute_job(worker, job['args'])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
define_method(:perform_one) do
|
50
|
+
raise(EmptyQueueError, "perform_one called with empty job queue") if jobs.empty?
|
51
|
+
job = jobs.shift
|
52
|
+
worker = new
|
53
|
+
worker.jid = job['jid']
|
54
|
+
execute_job(worker, job['args'])
|
55
|
+
end
|
56
|
+
|
57
|
+
define_method(:execute_job) do |worker, args|
|
58
|
+
worker.perform(*args)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# rubocop:enable all
|
63
|
+
|
64
|
+
module_function :override_methods
|
65
|
+
private_class_method :override_methods
|
66
|
+
end
|
67
|
+
|
68
|
+
include Overrides
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module Sidekiq
|
74
|
+
module Worker
|
75
|
+
module Overrides
|
76
|
+
def self.included(base)
|
77
|
+
base.extend ClassMethods
|
78
|
+
|
79
|
+
base.class_eval do
|
80
|
+
class << self
|
81
|
+
alias_method :clear_all_orig, :clear_all
|
82
|
+
alias_method :clear_all, :clear_all_ext
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
module ClassMethods
|
88
|
+
def clear_all_ext
|
89
|
+
clear_all_orig
|
90
|
+
unique_prefix = SidekiqUniqueJobs.config.unique_prefix
|
91
|
+
unique_keys = Sidekiq.redis { |conn| conn.keys("#{unique_prefix}*") }
|
92
|
+
return if unique_keys.empty?
|
93
|
+
|
94
|
+
Sidekiq.redis { |conn| conn.del(*unique_keys) }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
include Overrides
|
100
|
+
end
|
101
|
+
end
|
data/spec/lib/client_spec.rb
CHANGED
@@ -169,5 +169,25 @@ describe 'Client' do
|
|
169
169
|
|
170
170
|
expect(actual_expires_at).to be_within(2).of(expected_expires_at)
|
171
171
|
end
|
172
|
+
|
173
|
+
it 'logs duplicate payload when config turned on' do
|
174
|
+
expect(Sidekiq.logger).to receive(:warn).with(/^payload is not unique/)
|
175
|
+
|
176
|
+
QueueWorker.sidekiq_options unique: true, log_duplicate_payload: true
|
177
|
+
|
178
|
+
2.times { Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2]) }
|
179
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
180
|
+
expect(result).to eq 1
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'does not log duplicate payload when config turned off' do
|
184
|
+
expect(Sidekiq.logger).to_not receive(:warn).with(/^payload is not unique/)
|
185
|
+
|
186
|
+
QueueWorker.sidekiq_options unique: true, log_duplicate_payload: false
|
187
|
+
|
188
|
+
2.times { Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2]) }
|
189
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
190
|
+
expect(result).to eq 1
|
191
|
+
end
|
172
192
|
end
|
173
193
|
end
|
@@ -9,21 +9,110 @@ require 'rspec-sidekiq'
|
|
9
9
|
|
10
10
|
describe 'When Sidekiq::Testing is enabled' do
|
11
11
|
describe 'when set to :fake!', sidekiq: :fake do
|
12
|
+
before do
|
13
|
+
Sidekiq.redis = REDIS
|
14
|
+
Sidekiq.redis(&:flushdb)
|
15
|
+
end
|
16
|
+
|
12
17
|
context 'with unique worker' do
|
13
18
|
it 'does not push duplicate messages' do
|
14
19
|
param = 'work'
|
15
20
|
expect(UniqueWorker.jobs.size).to eq(0)
|
16
|
-
UniqueWorker.perform_async(param)
|
21
|
+
expect(UniqueWorker.perform_async(param)).to_not be_nil
|
17
22
|
expect(UniqueWorker.jobs.size).to eq(1)
|
18
23
|
expect(UniqueWorker).to have_enqueued_job(param)
|
24
|
+
expect(UniqueWorker.perform_async(param)).to be_nil
|
25
|
+
expect(UniqueWorker.jobs.size).to eq(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'unlocks jobs after draining a worker' do
|
29
|
+
param = 'work'
|
30
|
+
param2 = 'more work'
|
31
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
32
|
+
UniqueWorker.perform_async(param)
|
33
|
+
UniqueWorker.perform_async(param2)
|
34
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
35
|
+
UniqueWorker.drain
|
36
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
37
|
+
UniqueWorker.perform_async(param)
|
38
|
+
UniqueWorker.perform_async(param2)
|
39
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'unlocks a single job when calling perform_one' do
|
43
|
+
param = 'work'
|
44
|
+
param2 = 'more work'
|
45
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
46
|
+
UniqueWorker.perform_async(param)
|
47
|
+
UniqueWorker.perform_async(param2)
|
48
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
49
|
+
UniqueWorker.perform_one
|
50
|
+
expect(UniqueWorker.jobs.size).to eq(1)
|
51
|
+
UniqueWorker.perform_async(param2)
|
52
|
+
expect(UniqueWorker.jobs.size).to eq(1)
|
53
|
+
UniqueWorker.perform_async(param)
|
54
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'unlocks jobs cleared from a single worker' do
|
58
|
+
param = 'work'
|
59
|
+
param2 = 'more work'
|
60
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
61
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(0)
|
62
|
+
UniqueWorker.perform_async(param)
|
63
|
+
UniqueWorker.perform_async(param2)
|
64
|
+
AnotherUniqueWorker.perform_async(param)
|
65
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
66
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(1)
|
67
|
+
UniqueWorker.clear
|
68
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
69
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(1)
|
70
|
+
UniqueWorker.perform_async(param)
|
71
|
+
UniqueWorker.perform_async(param2)
|
72
|
+
AnotherUniqueWorker.perform_async(param)
|
73
|
+
expect(UniqueWorker.jobs.size).to eq(2)
|
74
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(1)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'handles clearing an empty worker queue' do
|
78
|
+
param = 'work'
|
79
|
+
UniqueWorker.perform_async(param)
|
80
|
+
UniqueWorker.clear
|
81
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
82
|
+
expect { UniqueWorker.clear }.not_to raise_error
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'unlocks jobs when all workers are cleared' do
|
86
|
+
param = 'work'
|
87
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
88
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(0)
|
89
|
+
UniqueWorker.perform_async(param)
|
90
|
+
AnotherUniqueWorker.perform_async(param)
|
91
|
+
expect(UniqueWorker.jobs.size).to eq(1)
|
92
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(1)
|
93
|
+
Sidekiq::Worker.clear_all
|
94
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
95
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(0)
|
19
96
|
UniqueWorker.perform_async(param)
|
97
|
+
AnotherUniqueWorker.perform_async(param)
|
20
98
|
expect(UniqueWorker.jobs.size).to eq(1)
|
99
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(1)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'handles clearing all workers when there are no jobs' do
|
103
|
+
param = 'work'
|
104
|
+
UniqueWorker.perform_async(param)
|
105
|
+
AnotherUniqueWorker.perform_async(param)
|
106
|
+
Sidekiq::Worker.clear_all
|
107
|
+
expect(UniqueWorker.jobs.size).to eq(0)
|
108
|
+
expect(AnotherUniqueWorker.jobs.size).to eq(0)
|
109
|
+
expect { Sidekiq::Worker.jobs.size }.not_to raise_error
|
21
110
|
end
|
22
111
|
|
23
112
|
it 'adds the unique_hash to the message' do
|
24
113
|
param = 'hash'
|
25
114
|
hash = SidekiqUniqueJobs::PayloadHelper.get_payload(UniqueWorker, :working, [param])
|
26
|
-
UniqueWorker.perform_async(param)
|
115
|
+
expect(UniqueWorker.perform_async(param)).to_not be_nil
|
27
116
|
expect(UniqueWorker.jobs.size).to eq(1)
|
28
117
|
expect(UniqueWorker.jobs.first['unique_hash']).to eq(hash)
|
29
118
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,7 +18,7 @@ Sidekiq::Testing.disable!
|
|
18
18
|
|
19
19
|
require 'sidekiq/redis_connection'
|
20
20
|
redis_url = ENV['REDIS_URL'] || 'redis://localhost/15'
|
21
|
-
REDIS = Sidekiq::RedisConnection.create(url: redis_url, namespace: '
|
21
|
+
REDIS = Sidekiq::RedisConnection.create(url: redis_url, namespace: 'sidekiq-unique-jobs-testing')
|
22
22
|
|
23
23
|
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
|
24
24
|
RSpec.configure do |_config|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AnotherUniqueWorker
|
2
|
+
include Sidekiq::Worker
|
3
|
+
sidekiq_options queue: :working, retry: 1, backtrace: 10
|
4
|
+
sidekiq_options unique: true
|
5
|
+
|
6
|
+
sidekiq_retries_exhausted do |msg|
|
7
|
+
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform(*)
|
11
|
+
# NO-OP
|
12
|
+
end
|
13
|
+
end
|
data/spec/support/my_worker.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-unique-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -143,6 +143,9 @@ files:
|
|
143
143
|
- gemfiles/sidekiq_2.16.gemfile
|
144
144
|
- gemfiles/sidekiq_2.17.gemfile
|
145
145
|
- gemfiles/sidekiq_3.0.gemfile
|
146
|
+
- gemfiles/sidekiq_3.1.gemfile
|
147
|
+
- gemfiles/sidekiq_3.2.gemfile
|
148
|
+
- gemfiles/sidekiq_3.3.gemfile
|
146
149
|
- gemfiles/sidekiq_develop.gemfile
|
147
150
|
- lib/sidekiq-unique-jobs.rb
|
148
151
|
- lib/sidekiq_unique_jobs/config.rb
|
@@ -150,23 +153,24 @@ files:
|
|
150
153
|
- lib/sidekiq_unique_jobs/connectors/redis_pool.rb
|
151
154
|
- lib/sidekiq_unique_jobs/connectors/sidekiq_redis.rb
|
152
155
|
- lib/sidekiq_unique_jobs/connectors/testing.rb
|
156
|
+
- lib/sidekiq_unique_jobs/inline_testing.rb
|
153
157
|
- lib/sidekiq_unique_jobs/middleware.rb
|
154
158
|
- lib/sidekiq_unique_jobs/middleware/client/strategies/testing_inline.rb
|
155
159
|
- lib/sidekiq_unique_jobs/middleware/client/strategies/unique.rb
|
156
160
|
- lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb
|
157
161
|
- lib/sidekiq_unique_jobs/middleware/server/unique_jobs.rb
|
158
162
|
- lib/sidekiq_unique_jobs/payload_helper.rb
|
163
|
+
- lib/sidekiq_unique_jobs/sidekiq_test_overrides.rb
|
159
164
|
- lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb
|
160
|
-
- lib/sidekiq_unique_jobs/testing.rb
|
161
165
|
- lib/sidekiq_unique_jobs/version.rb
|
162
166
|
- sidekiq-unique-jobs.gemspec
|
163
|
-
- spec/lib/.sidekiq_testing_enabled_spec.rb.swp
|
164
167
|
- spec/lib/client_spec.rb
|
165
168
|
- spec/lib/middleware/server/unique_jobs_spec.rb
|
166
169
|
- spec/lib/sidekiq_testing_enabled_spec.rb
|
167
170
|
- spec/lib/sidekiq_unique_ext_spec.rb
|
168
171
|
- spec/lib/unlock_order_spec.rb
|
169
172
|
- spec/spec_helper.rb
|
173
|
+
- spec/support/another_unique_worker.rb
|
170
174
|
- spec/support/my_worker.rb
|
171
175
|
- spec/support/sidekiq_meta.rb
|
172
176
|
- spec/support/unique_worker.rb
|
Binary file
|