sidekiq-unique-jobs 3.0.2 → 3.0.5
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/.rubocop.yml +36 -0
- data/.travis.yml +0 -2
- data/Appraisals +2 -1
- data/CHANGELOG.md +4 -4
- data/Gemfile +1 -3
- data/README.md +2 -2
- data/Rakefile +6 -4
- data/gemfiles/sidekiq_2.15.gemfile +1 -3
- data/gemfiles/sidekiq_2.16.gemfile +1 -3
- data/gemfiles/sidekiq_2.17.gemfile +1 -3
- data/gemfiles/sidekiq_3.0.gemfile +1 -3
- data/gemfiles/sidekiq_develop.gemfile +2 -4
- data/lib/sidekiq_unique_jobs.rb +27 -0
- data/lib/sidekiq_unique_jobs/config.rb +47 -0
- data/lib/sidekiq_unique_jobs/connectors.rb +16 -0
- data/lib/sidekiq_unique_jobs/connectors/redis_pool.rb +10 -0
- data/lib/sidekiq_unique_jobs/connectors/sidekiq_redis.rb +9 -0
- data/lib/sidekiq_unique_jobs/connectors/testing.rb +10 -0
- data/lib/{sidekiq-unique-jobs → sidekiq_unique_jobs}/middleware.rb +3 -3
- data/lib/sidekiq_unique_jobs/middleware/client/strategies/testing_inline.rb +25 -0
- data/lib/sidekiq_unique_jobs/middleware/client/strategies/unique.rb +72 -0
- data/lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb +48 -0
- data/lib/{sidekiq-unique-jobs → sidekiq_unique_jobs}/middleware/server/unique_jobs.rb +14 -13
- data/lib/sidekiq_unique_jobs/payload_helper.rb +42 -0
- data/lib/{sidekiq-unique-jobs → sidekiq_unique_jobs}/testing.rb +2 -2
- data/lib/{sidekiq-unique-jobs → sidekiq_unique_jobs}/version.rb +1 -1
- data/sidekiq-unique-jobs.gemspec +12 -11
- data/spec/lib/.sidekiq_testing_enabled_spec.rb.swp +0 -0
- data/spec/lib/client_spec.rb +56 -44
- data/spec/lib/middleware/server/unique_jobs_spec.rb +16 -16
- data/spec/lib/sidekiq_testing_enabled_spec.rb +90 -8
- data/spec/lib/unlock_order_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -6
- data/spec/support/my_worker.rb +3 -3
- data/spec/support/sidekiq_meta.rb +3 -6
- data/spec/support/unique_worker.rb +3 -3
- metadata +35 -13
- data/lib/sidekiq-unique-jobs.rb +0 -11
- data/lib/sidekiq-unique-jobs/config.rb +0 -35
- data/lib/sidekiq-unique-jobs/middleware/client/unique_jobs.rb +0 -101
- data/lib/sidekiq-unique-jobs/payload_helper.rb +0 -30
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'digest'
|
2
|
+
require 'sidekiq_unique_jobs/connectors'
|
2
3
|
|
3
4
|
module SidekiqUniqueJobs
|
4
5
|
module Middleware
|
@@ -6,10 +7,10 @@ module SidekiqUniqueJobs
|
|
6
7
|
class UniqueJobs
|
7
8
|
attr_reader :unlock_order, :redis_pool
|
8
9
|
|
9
|
-
def call(worker, item,
|
10
|
+
def call(worker, item, _queue, redis_pool = nil)
|
10
11
|
@redis_pool = redis_pool
|
11
12
|
|
12
|
-
|
13
|
+
decide_unlock_order(worker.class)
|
13
14
|
lock_key = payload_hash(item)
|
14
15
|
unlocked = before_yield? ? unlock(lock_key).inspect : 0
|
15
16
|
|
@@ -20,12 +21,12 @@ module SidekiqUniqueJobs
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
+
def decide_unlock_order(klass)
|
24
25
|
@unlock_order = if unlock_order_configured?(klass)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
klass.get_sidekiq_options['unique_unlock_order']
|
27
|
+
else
|
28
|
+
default_unlock_order
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
def unlock_order_configured?(klass)
|
@@ -34,7 +35,7 @@ module SidekiqUniqueJobs
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def default_unlock_order
|
37
|
-
SidekiqUniqueJobs
|
38
|
+
SidekiqUniqueJobs.config.default_unlock_order
|
38
39
|
end
|
39
40
|
|
40
41
|
def before_yield?
|
@@ -52,16 +53,16 @@ module SidekiqUniqueJobs
|
|
52
53
|
end
|
53
54
|
|
54
55
|
def unlock(payload_hash)
|
55
|
-
|
56
|
-
redis_pool.with { |conn| conn.del(payload_hash) }
|
57
|
-
else
|
58
|
-
Sidekiq.redis { |conn| conn.del(payload_hash) }
|
59
|
-
end
|
56
|
+
conn.del(payload_hash)
|
60
57
|
end
|
61
58
|
|
62
59
|
def logger
|
63
60
|
Sidekiq.logger
|
64
61
|
end
|
62
|
+
|
63
|
+
def conn
|
64
|
+
SidekiqUniqueJobs::Connectors.conn(redis_pool)
|
65
|
+
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SidekiqUniqueJobs
|
2
|
+
class PayloadHelper
|
3
|
+
def self.config
|
4
|
+
SidekiqUniqueJobs.config
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.get_payload(klass, queue, *args)
|
8
|
+
unique_on_all_queues = false
|
9
|
+
if config.unique_args_enabled
|
10
|
+
worker_class = klass.constantize
|
11
|
+
args = yield_unique_args(worker_class, *args)
|
12
|
+
unique_on_all_queues =
|
13
|
+
worker_class.get_sidekiq_options['unique_on_all_queues']
|
14
|
+
end
|
15
|
+
md5_arguments = { class: klass, args: args }
|
16
|
+
md5_arguments[:queue] = queue unless unique_on_all_queues
|
17
|
+
"#{config.unique_prefix}:" \
|
18
|
+
"#{Digest::MD5.hexdigest(Sidekiq.dump_json(md5_arguments))}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.yield_unique_args(worker_class, args)
|
22
|
+
unique_args = worker_class.get_sidekiq_options['unique_args']
|
23
|
+
filtered_args(worker_class, unique_args, args)
|
24
|
+
rescue NameError
|
25
|
+
# fallback to not filtering args when class can't be instantiated
|
26
|
+
args
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.filtered_args(worker_class, unique_args, args)
|
30
|
+
case unique_args
|
31
|
+
when Proc
|
32
|
+
unique_args.call(args)
|
33
|
+
when Symbol
|
34
|
+
if worker_class.respond_to?(unique_args)
|
35
|
+
worker_class.send(unique_args, *args)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
args
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/sidekiq-unique-jobs.gemspec
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/
|
2
|
+
require File.expand_path('../lib/sidekiq_unique_jobs/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
7
|
-
gem.description = gem.summary =
|
8
|
-
gem.homepage =
|
9
|
-
gem.license =
|
5
|
+
gem.authors = ['Mikael Henriksson']
|
6
|
+
gem.email = ['mikael@zoolutions.se']
|
7
|
+
gem.description = gem.summary = 'The unique jobs that were removed from sidekiq'
|
8
|
+
gem.homepage = 'https://github.com/mhenrixon/sidekiq-unique-jobs'
|
9
|
+
gem.license = 'LGPL-3.0'
|
10
10
|
|
11
11
|
# gem.executables = ['']
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
13
13
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
14
|
-
gem.name =
|
15
|
-
gem.require_paths = [
|
14
|
+
gem.name = 'sidekiq-unique-jobs'
|
15
|
+
gem.require_paths = ['lib']
|
16
16
|
gem.version = SidekiqUniqueJobs::VERSION
|
17
|
-
gem.add_dependency
|
18
|
-
gem.
|
19
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
17
|
+
gem.add_dependency 'sidekiq', '>= 2.6'
|
18
|
+
gem.add_development_dependency 'mock_redis'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 3.1.0'
|
20
20
|
gem.add_development_dependency 'rake'
|
21
21
|
gem.add_development_dependency 'rspec-sidekiq'
|
22
22
|
gem.add_development_dependency 'activesupport', '>= 3'
|
23
|
+
gem.add_development_dependency 'rubocop'
|
23
24
|
gem.add_development_dependency 'simplecov'
|
24
25
|
end
|
Binary file
|
data/spec/lib/client_spec.rb
CHANGED
@@ -1,98 +1,98 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'celluloid'
|
3
3
|
require 'sidekiq/worker'
|
4
|
-
require
|
4
|
+
require 'sidekiq_unique_jobs'
|
5
5
|
require 'sidekiq/scheduled'
|
6
|
-
require '
|
6
|
+
require 'sidekiq_unique_jobs/middleware/server/unique_jobs'
|
7
7
|
|
8
|
-
describe
|
8
|
+
describe 'Client' do
|
9
9
|
describe 'with real redis' do
|
10
10
|
before do
|
11
11
|
Sidekiq.redis = REDIS
|
12
|
-
Sidekiq.redis
|
13
|
-
QueueWorker.sidekiq_options :
|
12
|
+
Sidekiq.redis(&:flushdb)
|
13
|
+
QueueWorker.sidekiq_options unique: nil, unique_job_expiration: nil
|
14
14
|
end
|
15
15
|
|
16
16
|
class QueueWorker
|
17
17
|
include Sidekiq::Worker
|
18
|
-
sidekiq_options :
|
19
|
-
def perform(
|
18
|
+
sidekiq_options queue: 'customqueue'
|
19
|
+
def perform(_x)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
class PlainClass
|
24
|
-
def run(
|
24
|
+
def run(_x)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'does not push duplicate messages when configured for unique only' do
|
29
|
-
QueueWorker.sidekiq_options :
|
29
|
+
QueueWorker.sidekiq_options unique: true
|
30
30
|
10.times { Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2]) }
|
31
|
-
result = Sidekiq.redis {|c| c.llen(
|
31
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
32
32
|
expect(result).to eq 1
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'does push duplicate messages to different queues' do
|
36
|
-
QueueWorker.sidekiq_options :
|
36
|
+
QueueWorker.sidekiq_options unique: true
|
37
37
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
38
38
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue2', 'args' => [1, 2])
|
39
|
-
q1_length = Sidekiq.redis {|c| c.llen(
|
40
|
-
q2_length = Sidekiq.redis {|c| c.llen(
|
39
|
+
q1_length = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
40
|
+
q2_length = Sidekiq.redis { |c| c.llen('queue:customqueue2') }
|
41
41
|
expect(q1_length).to eq 1
|
42
42
|
expect(q2_length).to eq 1
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'does not queue duplicates when when calling delay' do
|
46
46
|
10.times { PlainClass.delay(unique: true, queue: 'customqueue').run(1) }
|
47
|
-
result = Sidekiq.redis {|c| c.llen(
|
47
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
48
48
|
expect(result).to eq 1
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'does not schedule duplicates when calling perform_in' do
|
52
|
-
QueueWorker.sidekiq_options :
|
52
|
+
QueueWorker.sidekiq_options unique: true
|
53
53
|
10.times { QueueWorker.perform_in(60, [1, 2]) }
|
54
|
-
result = Sidekiq.redis { |c| c.zcount(
|
54
|
+
result = Sidekiq.redis { |c| c.zcount('schedule', -1, Time.now.to_f + 2 * 60) }
|
55
55
|
expect(result).to eq 1
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'enqueues previously scheduled job' do
|
59
|
-
QueueWorker.sidekiq_options :
|
59
|
+
QueueWorker.sidekiq_options unique: true
|
60
60
|
QueueWorker.perform_in(60 * 60, 1, 2)
|
61
61
|
|
62
62
|
# time passes and the job is pulled off the schedule:
|
63
63
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
64
64
|
|
65
|
-
result = Sidekiq.redis {|c| c.llen(
|
65
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
66
66
|
expect(result).to eq 1
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'sets an expiration when provided by sidekiq options' do
|
70
70
|
one_hour_expiration = 60 * 60
|
71
|
-
QueueWorker.sidekiq_options :
|
71
|
+
QueueWorker.sidekiq_options unique: true, unique_job_expiration: one_hour_expiration
|
72
72
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
73
73
|
|
74
|
-
payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload(
|
75
|
-
actual_expires_at = Sidekiq.redis {|c| c.ttl(payload_hash) }
|
74
|
+
payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload('QueueWorker', 'customqueue', [1, 2])
|
75
|
+
actual_expires_at = Sidekiq.redis { |c| c.ttl(payload_hash) }
|
76
76
|
|
77
|
-
|
77
|
+
Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
78
78
|
expect(actual_expires_at).to be_within(2).of(one_hour_expiration)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'does push duplicate messages when not configured for unique only' do
|
82
|
-
QueueWorker.sidekiq_options :
|
82
|
+
QueueWorker.sidekiq_options unique: false
|
83
83
|
10.times { Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2]) }
|
84
|
-
expect(Sidekiq.redis {|c| c.llen(
|
84
|
+
expect(Sidekiq.redis { |c| c.llen('queue:customqueue') }).to eq 10
|
85
85
|
|
86
|
-
result = Sidekiq.redis {|c| c.llen(
|
86
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
87
87
|
expect(result).to eq 10
|
88
88
|
end
|
89
89
|
|
90
90
|
describe 'when unique_args is defined' do
|
91
|
-
before { SidekiqUniqueJobs
|
92
|
-
after { SidekiqUniqueJobs
|
91
|
+
before { SidekiqUniqueJobs.config.unique_args_enabled = true }
|
92
|
+
after { SidekiqUniqueJobs.config.unique_args_enabled = false }
|
93
93
|
|
94
94
|
class QueueWorkerWithFilterMethod < QueueWorker
|
95
|
-
sidekiq_options :
|
95
|
+
sidekiq_options unique: true, unique_args: :args_filter
|
96
96
|
|
97
97
|
def self.args_filter(*args)
|
98
98
|
args.first
|
@@ -100,19 +100,27 @@ describe "Client" do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
class QueueWorkerWithFilterProc < QueueWorker
|
103
|
-
# slightly contrived example of munging args to the
|
104
|
-
|
103
|
+
# slightly contrived example of munging args to the
|
104
|
+
# worker and removing a random bit.
|
105
|
+
sidekiq_options unique: true, unique_args: (lambda do |args|
|
106
|
+
a = args.last.dup
|
107
|
+
a.delete(:random)
|
108
|
+
[args.first, a]
|
109
|
+
end)
|
105
110
|
end
|
106
111
|
|
107
112
|
it 'does not push duplicate messages based on args filter method' do
|
108
113
|
expect(QueueWorkerWithFilterMethod).to respond_to(:args_filter)
|
109
114
|
expect(QueueWorkerWithFilterMethod.get_sidekiq_options['unique_args']).to eq :args_filter
|
110
115
|
|
111
|
-
|
112
|
-
|
113
|
-
|
116
|
+
(0..10).each do |i|
|
117
|
+
Sidekiq::Client.push(
|
118
|
+
'class' => QueueWorkerWithFilterMethod,
|
119
|
+
'queue' => 'customqueue',
|
120
|
+
'args' => [1, i]
|
121
|
+
)
|
114
122
|
end
|
115
|
-
result = Sidekiq.redis {|c| c.llen(
|
123
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
116
124
|
expect(result).to eq 1
|
117
125
|
end
|
118
126
|
|
@@ -120,20 +128,24 @@ describe "Client" do
|
|
120
128
|
expect(QueueWorkerWithFilterProc.get_sidekiq_options['unique_args']).to be_a(Proc)
|
121
129
|
|
122
130
|
10.times do
|
123
|
-
Sidekiq::Client.push(
|
131
|
+
Sidekiq::Client.push(
|
132
|
+
'class' => QueueWorkerWithFilterProc,
|
133
|
+
'queue' => 'customqueue',
|
134
|
+
'args' => [1, { random: rand, name: 'foobar' }]
|
135
|
+
)
|
124
136
|
end
|
125
|
-
result = Sidekiq.redis {|c| c.llen(
|
137
|
+
result = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
126
138
|
expect(result).to eq 1
|
127
139
|
end
|
128
140
|
|
129
141
|
describe 'when unique_on_all_queues is set' do
|
130
|
-
before { QueueWorker.sidekiq_options :
|
131
|
-
before { QueueWorker.sidekiq_options :
|
142
|
+
before { QueueWorker.sidekiq_options unique: true, unique_on_all_queues: true }
|
143
|
+
before { QueueWorker.sidekiq_options unique: true }
|
132
144
|
it 'does not push duplicate messages on different queues' do
|
133
145
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
134
146
|
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue2', 'args' => [1, 2])
|
135
|
-
q1_length = Sidekiq.redis {|c| c.llen(
|
136
|
-
q2_length = Sidekiq.redis {|c| c.llen(
|
147
|
+
q1_length = Sidekiq.redis { |c| c.llen('queue:customqueue') }
|
148
|
+
q2_length = Sidekiq.redis { |c| c.llen('queue:customqueue2') }
|
137
149
|
expect(q1_length).to eq 1
|
138
150
|
expect(q2_length).to eq 0
|
139
151
|
end
|
@@ -145,16 +157,16 @@ describe "Client" do
|
|
145
157
|
# jobs are set around the same time as the scheduled job itself feel free to improve.
|
146
158
|
it 'expires the payload_hash when a scheduled job is scheduled at' do
|
147
159
|
require 'active_support/all'
|
148
|
-
QueueWorker.sidekiq_options :
|
160
|
+
QueueWorker.sidekiq_options unique: true
|
149
161
|
|
150
162
|
at = 15.minutes.from_now
|
151
|
-
expected_expires_at = (Time.at(at) - Time.now.utc) + SidekiqUniqueJobs
|
163
|
+
expected_expires_at = (Time.at(at) - Time.now.utc) + SidekiqUniqueJobs.config.default_expiration
|
152
164
|
|
153
165
|
QueueWorker.perform_in(at, 'mike')
|
154
|
-
payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload(
|
166
|
+
payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload('QueueWorker', 'customqueue', ['mike'])
|
155
167
|
|
156
168
|
# deconstruct this into a time format we can use to get a decent delta for
|
157
|
-
actual_expires_at = Sidekiq.redis {|c| c.ttl(payload_hash) }
|
169
|
+
actual_expires_at = Sidekiq.redis { |c| c.ttl(payload_hash) }
|
158
170
|
|
159
171
|
expect(actual_expires_at).to be_within(2).of(expected_expires_at)
|
160
172
|
end
|
@@ -6,48 +6,48 @@ module SidekiqUniqueJobs
|
|
6
6
|
describe UniqueJobs do
|
7
7
|
describe '#unlock_order_configured?' do
|
8
8
|
context "when class isn't a Sidekiq::Worker" do
|
9
|
-
it
|
9
|
+
it 'returns false' do
|
10
10
|
expect(subject.unlock_order_configured?(Class))
|
11
11
|
.to eq(false)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context
|
16
|
-
it
|
15
|
+
context 'when get_sidekiq_options[:unique_unlock_order] is nil' do
|
16
|
+
it 'returns false' do
|
17
17
|
expect(subject.unlock_order_configured?(MyWorker))
|
18
18
|
.to eq(false)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'returns true when unique_unlock_order has been set' do
|
23
23
|
UniqueWorker.sidekiq_options unique_unlock_order: :before_yield
|
24
24
|
expect(subject.unlock_order_configured?(UniqueWorker))
|
25
25
|
.to eq(true)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe '#
|
30
|
-
context
|
31
|
-
it
|
29
|
+
describe '#decide_unlock_order' do
|
30
|
+
context 'when worker has specified unique_unlock_order' do
|
31
|
+
it 'changes unlock_order to the configured value' do
|
32
32
|
UniqueWorker.sidekiq_options unique_unlock_order: :before_yield
|
33
33
|
expect do
|
34
|
-
subject.
|
34
|
+
subject.decide_unlock_order(UniqueWorker)
|
35
35
|
end.to change { subject.unlock_order }.to :before_yield
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when worker hasn't specified unique_unlock_order" do
|
40
|
-
it
|
41
|
-
SidekiqUniqueJobs
|
40
|
+
it 'falls back to configured default_unlock_order' do
|
41
|
+
SidekiqUniqueJobs.config.default_unlock_order = :before_yield
|
42
42
|
expect do
|
43
|
-
subject.
|
43
|
+
subject.decide_unlock_order(UniqueWorker)
|
44
44
|
end.to change { subject.unlock_order }.to :before_yield
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
describe '#before_yield?' do
|
50
|
-
it
|
50
|
+
it 'returns unlock_order == :before_yield' do
|
51
51
|
allow(subject).to receive(:unlock_order).and_return(:after_yield)
|
52
52
|
expect(subject.before_yield?).to eq(false)
|
53
53
|
|
@@ -57,7 +57,7 @@ module SidekiqUniqueJobs
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#after_yield?' do
|
60
|
-
it
|
60
|
+
it 'returns unlock_order == :before_yield' do
|
61
61
|
allow(subject).to receive(:unlock_order).and_return(:before_yield)
|
62
62
|
expect(subject.after_yield?).to eq(false)
|
63
63
|
|
@@ -68,14 +68,14 @@ module SidekiqUniqueJobs
|
|
68
68
|
|
69
69
|
describe '#default_unlock_order' do
|
70
70
|
it 'returns the default value from config' do
|
71
|
-
SidekiqUniqueJobs
|
71
|
+
SidekiqUniqueJobs.config.default_unlock_order = :before_yield
|
72
72
|
expect(subject.default_unlock_order).to eq(:before_yield)
|
73
73
|
|
74
|
-
SidekiqUniqueJobs
|
74
|
+
SidekiqUniqueJobs.config.default_unlock_order = :after_yield
|
75
75
|
expect(subject.default_unlock_order).to eq(:after_yield)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
-
end
|
81
|
+
end
|