sidekiq-unique-jobs 4.0.15 → 4.0.16
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/.codeclimate.yml +22 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +23 -12
- data/Gemfile +1 -1
- data/README.md +7 -1
- data/lib/sidekiq-unique-jobs.rb +2 -1
- data/lib/sidekiq_unique_jobs/config.rb +2 -1
- data/lib/sidekiq_unique_jobs/constants.rb +2 -1
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +1 -1
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +7 -1
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +3 -3
- data/lib/sidekiq_unique_jobs/timeout_calculator.rb +36 -13
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/rails_example/app/workers/simple_worker.rb +1 -1
- data/redis/synchronize.lua +3 -2
- data/spec/jobs/long_running_job.rb +7 -0
- data/spec/jobs/simple_worker.rb +1 -1
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +2 -1
- data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +27 -0
- data/spec/lib/sidekiq_unique_jobs/queue_lock_timeout_calculator_spec.rb +47 -0
- data/spec/lib/sidekiq_unique_jobs/run_lock_timeout_calculator_spec.rb +36 -0
- data/spec/lib/sidekiq_unique_jobs/timeout_calculator_spec.rb +9 -19
- data/spec/spec_helper.rb +1 -67
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa74d419e8964813243a427ec860730ac44dfe36
|
4
|
+
data.tar.gz: e4e1850f812e286a59e4de00c9ea2f6b4ff6d392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d6e3e9c95acfc333bb8d697121d53a2a8208fbca08ce9790c5457f08f6680c7469d7493cdc5eeb2bf49046c4094ebf23cb5a1449e63793169a9ad3d5d9bffc
|
7
|
+
data.tar.gz: 810c75a9aafd58ef30cb4a99568ac9a24d49062fe69ef7a11512e9c261d5e2e8af730a109c4213f083024dcc9ae10d0f6d9c56ae41c80a7ed68f41df8b34df40
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
engines:
|
2
|
+
bundler-audit:
|
3
|
+
enabled: true
|
4
|
+
fixme:
|
5
|
+
enabled: true
|
6
|
+
duplication:
|
7
|
+
enabled: true
|
8
|
+
rubocop:
|
9
|
+
enabled: true
|
10
|
+
golint:
|
11
|
+
enabled: true
|
12
|
+
ratings:
|
13
|
+
paths:
|
14
|
+
- lib/**
|
15
|
+
- bin/**
|
16
|
+
- "**.rb"
|
17
|
+
exclude_paths:
|
18
|
+
- spec/
|
19
|
+
- gemfiles/
|
20
|
+
- rails_example/
|
21
|
+
- redis/
|
22
|
+
- tmp/
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## v4.0.16
|
2
|
+
|
3
|
+
- Allow run & queue lock timeout (expiration) to be different [#164](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/164)
|
4
|
+
- Fix a bug with loading sidekiq test overrides ([#167](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/167)
|
5
|
+
|
6
|
+
## v4.0.15
|
7
|
+
|
8
|
+
- Close [#156](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/156)
|
9
|
+
- Close [#158](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/158)
|
10
|
+
- Style fixes and some minor adjustments to the console/cmd line app
|
11
|
+
|
1
12
|
## v4.0.13
|
2
13
|
|
3
14
|
- Allow deleting locks by jid
|
@@ -5,19 +16,19 @@
|
|
5
16
|
## v4.0.12
|
6
17
|
|
7
18
|
- Allow jobs to be pushed to processing
|
8
|
-
- Close #150
|
9
|
-
- Close #151
|
10
|
-
- Close #146
|
11
|
-
- Close #136
|
12
|
-
- Close #133
|
19
|
+
- Close [#150](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/150)
|
20
|
+
- Close [#151](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/151)
|
21
|
+
- Close [#146](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/146)
|
22
|
+
- Close [#136](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/136)
|
23
|
+
- Close [#133](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/133)
|
13
24
|
|
14
25
|
## v4.0.11
|
15
26
|
|
16
|
-
- Always load forwardable
|
27
|
+
- Always load forwardable [#152](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/152#issuecomment-164199978)
|
17
28
|
|
18
29
|
## v4.0.10
|
19
30
|
|
20
|
-
- Fix https://github.com/mhenrixon/sidekiq-unique-jobs/issues/152
|
31
|
+
- Fix [#152](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/152)
|
21
32
|
- Minor improvement to internal esthetics
|
22
33
|
|
23
34
|
## v4.0.9
|
@@ -26,18 +37,18 @@
|
|
26
37
|
|
27
38
|
## v4.0.8
|
28
39
|
|
29
|
-
- Use unique arguments for the `WhileExecuting` lock (#127)
|
30
|
-
- Delicensed code (#132)
|
31
|
-
- Fix queuing unique jobs (#138)
|
40
|
+
- Use unique arguments for the `WhileExecuting` lock ([#127](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/127)
|
41
|
+
- Delicensed code ([#132](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/132)
|
42
|
+
- Fix queuing unique jobs ([#138](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/138)
|
32
43
|
|
33
44
|
## v4.0.7
|
34
45
|
|
35
|
-
- Use unique arguments for the `WhileExecuting` lock (#127)
|
46
|
+
- Use unique arguments for the `WhileExecuting` lock ([#127](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/127)
|
36
47
|
- See also https://github.com/mhenrixon/sidekiq-unique-jobs/releases/tag/v4.0.7
|
37
48
|
|
38
49
|
## v4.0.6
|
39
50
|
|
40
|
-
- Removes enforced uniqueness for all jobs (#127)
|
51
|
+
- Removes enforced uniqueness for all jobs ([#127](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/127)
|
41
52
|
|
42
53
|
## v4.0.5
|
43
54
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -101,7 +101,7 @@ For jobs scheduled in the future it is possible to set for how long the job
|
|
101
101
|
should be unique. The job will be unique for the number of seconds configured (default 30 minutes)
|
102
102
|
or until the job has been completed. Thus, the job will be unique for the shorter of the two. Note that Sidekiq versions before 3.0 will remove job keys after an hour, which means jobs can remain unique for at most an hour.
|
103
103
|
|
104
|
-
|
104
|
+
If you want the unique job to stick around even after it has been successfully
|
105
105
|
processed then just set `unique: :until_timeout`.
|
106
106
|
|
107
107
|
You can also control the expiration length of the uniqueness check. If you want to enforce uniqueness over a longer period than the default of 30 minutes then you can pass the number of seconds you want to use to the sidekiq options:
|
@@ -110,6 +110,12 @@ You can also control the expiration length of the uniqueness check. If you want
|
|
110
110
|
sidekiq_options unique: :until_timeout, unique_expiration: 120 * 60 # 2 hours
|
111
111
|
```
|
112
112
|
|
113
|
+
For locking modes (`:while_executing` and `:until_and_while_executing`) you can control the expiration length of the runtime uniqueness. If you want to enforce uniqueness over a longer period than the default of 60 seconds, then you can pass the number of seconds you want to use to the sidekiq options:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
sidekiq_options unique: :while_executing, run_lock_expiration: 2 * 60 # 2 minutes
|
117
|
+
```
|
118
|
+
|
113
119
|
Requiring the gem in your gemfile should be sufficient to enable unique jobs.
|
114
120
|
|
115
121
|
### Usage with ActiveJob
|
data/lib/sidekiq-unique-jobs.rb
CHANGED
@@ -23,7 +23,8 @@ module SidekiqUniqueJobs
|
|
23
23
|
def config
|
24
24
|
@config ||= Config.new(
|
25
25
|
unique_prefix: 'uniquejobs',
|
26
|
-
|
26
|
+
default_queue_lock_expiration: 30 * 60,
|
27
|
+
default_run_lock_expiration: 60,
|
27
28
|
default_lock: :while_executing,
|
28
29
|
redis_test_mode: :redis # :mock
|
29
30
|
)
|
@@ -5,6 +5,8 @@ module SidekiqUniqueJobs
|
|
5
5
|
JID_KEY ||= 'jid'.freeze
|
6
6
|
LOG_DUPLICATE_KEY ||= 'log_duplicate_payload'.freeze
|
7
7
|
QUEUE_KEY ||= 'queue'.freeze
|
8
|
+
QUEUE_LOCK_TIMEOUT_KEY ||= 'unique_expiration'.freeze
|
9
|
+
RUN_LOCK_TIMEOUT_KEY ||= 'run_lock_expiration'.freeze
|
8
10
|
TESTING_CONSTANT ||= 'Testing'.freeze
|
9
11
|
UNIQUE_KEY ||= 'unique'.freeze
|
10
12
|
UNIQUE_LOCK_KEY ||= 'unique_lock'.freeze
|
@@ -12,6 +14,5 @@ module SidekiqUniqueJobs
|
|
12
14
|
UNIQUE_PREFIX_KEY ||= 'unique_prefix'.freeze
|
13
15
|
UNIQUE_DIGEST_KEY ||= 'unique_digest'.freeze
|
14
16
|
UNIQUE_ON_ALL_QUEUES_KEY ||= 'unique_on_all_queues'.freeze
|
15
|
-
UNIQUE_TIMEOUT_KEY ||= 'unique_expiration'.freeze
|
16
17
|
UNIQUE_ARGS_ENABLED_KEY ||= 'unique_args_enabled'.freeze
|
17
18
|
end
|
@@ -24,7 +24,13 @@ module SidekiqUniqueJobs
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def locked?
|
27
|
-
Scripts.call(:synchronize, @redis_pool,
|
27
|
+
Scripts.call(:synchronize, @redis_pool,
|
28
|
+
keys: [@unique_digest],
|
29
|
+
argv: [Time.now.to_i, max_lock_time]) == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def max_lock_time
|
33
|
+
@max_lock_time ||= RunLockTimeoutCalculator.for_item(@item).seconds
|
28
34
|
end
|
29
35
|
|
30
36
|
def execute(_callback)
|
@@ -54,7 +54,7 @@ module Sidekiq
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
module
|
57
|
+
module UniqueExtension3_5
|
58
58
|
def self.included(base)
|
59
59
|
base.class_eval do
|
60
60
|
include SidekiqUniqueJobs::Unlockable
|
@@ -75,9 +75,9 @@ module Sidekiq
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
|
78
|
-
include
|
78
|
+
include UniqueExtension3_5 if sidekiq_version >= Gem::Version.new('3.5')
|
79
79
|
include UniqueExtension3_0 if sidekiq_version >= Gem::Version.new('3.0') &&
|
80
|
-
sidekiq_version < Gem::Version.new('3.
|
80
|
+
sidekiq_version < Gem::Version.new('3.5')
|
81
81
|
# rubocop:enable Style/ClassAndModuleCamelCase
|
82
82
|
end
|
83
83
|
|
@@ -8,27 +8,22 @@ module SidekiqUniqueJobs
|
|
8
8
|
@item = item
|
9
9
|
end
|
10
10
|
|
11
|
-
def seconds
|
12
|
-
time_until_scheduled + unique_expiration
|
13
|
-
end
|
14
|
-
|
15
11
|
def time_until_scheduled
|
16
12
|
scheduled = item[AT_KEY]
|
17
13
|
return 0 unless scheduled
|
18
14
|
(Time.at(scheduled) - Time.now.utc).to_i
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
22
|
-
|
23
|
-
(
|
24
|
-
worker_class_unique_expiration ||
|
25
|
-
SidekiqUniqueJobs.config.default_expiration
|
26
|
-
).to_i
|
17
|
+
def seconds
|
18
|
+
raise NotImplementedError
|
27
19
|
end
|
28
20
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
21
|
+
def worker_class_queue_lock_expiration
|
22
|
+
worker_class_expiration_for QUEUE_LOCK_TIMEOUT_KEY
|
23
|
+
end
|
24
|
+
|
25
|
+
def worker_class_run_lock_expiration
|
26
|
+
worker_class_expiration_for RUN_LOCK_TIMEOUT_KEY
|
32
27
|
end
|
33
28
|
|
34
29
|
def worker_class
|
@@ -37,6 +32,34 @@ module SidekiqUniqueJobs
|
|
37
32
|
|
38
33
|
private
|
39
34
|
|
35
|
+
def worker_class_expiration_for(key)
|
36
|
+
return unless worker_class.respond_to?(:get_sidekiq_options)
|
37
|
+
worker_class.get_sidekiq_options[key]
|
38
|
+
end
|
39
|
+
|
40
40
|
attr_reader :item
|
41
41
|
end
|
42
|
+
|
43
|
+
class RunLockTimeoutCalculator < TimeoutCalculator
|
44
|
+
def seconds
|
45
|
+
@seconds ||= (
|
46
|
+
worker_class_run_lock_expiration ||
|
47
|
+
SidekiqUniqueJobs.config.default_run_lock_expiration
|
48
|
+
).to_i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class QueueLockTimeoutCalculator < TimeoutCalculator
|
53
|
+
def seconds
|
54
|
+
queue_lock_expiration + time_until_scheduled
|
55
|
+
end
|
56
|
+
|
57
|
+
def queue_lock_expiration
|
58
|
+
@queue_lock_expiration ||=
|
59
|
+
(
|
60
|
+
worker_class_queue_lock_expiration ||
|
61
|
+
SidekiqUniqueJobs.config.default_queue_lock_expiration
|
62
|
+
).to_i
|
63
|
+
end
|
64
|
+
end
|
42
65
|
end
|
data/redis/synchronize.lua
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
local unique_key = KEYS[1]
|
2
2
|
local time = ARGV[1]
|
3
|
+
local expires = ARGV[2]
|
3
4
|
|
4
|
-
if redis.pcall('set', unique_key, time +
|
5
|
+
if redis.pcall('set', unique_key, time + expires, 'nx', 'ex', expires) then
|
5
6
|
return 1
|
6
7
|
end
|
7
8
|
|
8
9
|
local stored_time = redis.pcall('get', unique_key)
|
9
10
|
if stored_time and stored_time < time then
|
10
|
-
if redis.pcall('set', unique_key, time +
|
11
|
+
if redis.pcall('set', unique_key, time + expires, 'xx', 'ex', expires) then
|
11
12
|
return 1
|
12
13
|
end
|
13
14
|
end
|
data/spec/jobs/simple_worker.rb
CHANGED
@@ -225,7 +225,8 @@ RSpec.describe SidekiqUniqueJobs::Client::Middleware do
|
|
225
225
|
# jobs are set around the same time as the scheduled job itself feel free to improve.
|
226
226
|
it 'expires the digest when a scheduled job is scheduled at' do
|
227
227
|
expected_expires_at =
|
228
|
-
(Time.at(Time.now.to_i + 15 * 60) - Time.now.utc) +
|
228
|
+
(Time.at(Time.now.to_i + 15 * 60) - Time.now.utc) +
|
229
|
+
SidekiqUniqueJobs.config.default_queue_lock_expiration
|
229
230
|
jid = MyUniqueJob.perform_in(expected_expires_at, 'mike')
|
230
231
|
item = { 'class' => MyUniqueJob,
|
231
232
|
'queue' => 'customqueue',
|
@@ -31,6 +31,33 @@ RSpec.describe SidekiqUniqueJobs::Lock::WhileExecuting do
|
|
31
31
|
expect(x).to eq(10)
|
32
32
|
end
|
33
33
|
|
34
|
+
it 'expires the lock on the mutex object after run_lock_expiration if specified' do
|
35
|
+
mutexes = (1..10).map do
|
36
|
+
described_class.new(item)
|
37
|
+
end
|
38
|
+
|
39
|
+
worker = SidekiqUniqueJobs.worker_class_constantize(item[SidekiqUniqueJobs::CLASS_KEY])
|
40
|
+
allow(worker).to receive(:get_sidekiq_options)
|
41
|
+
.and_return('retry' => true,
|
42
|
+
'queue' => :dupsallowed,
|
43
|
+
'run_lock_expiration' => 0,
|
44
|
+
'unique' => :until_and_while_executing)
|
45
|
+
|
46
|
+
start_times = []
|
47
|
+
sleep_time = 0.1
|
48
|
+
mutexes.each_with_index.map do |m, i|
|
49
|
+
Thread.new do
|
50
|
+
m.synchronize do
|
51
|
+
start_times[i] = Time.now
|
52
|
+
sleep sleep_time
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end.map(&:join)
|
56
|
+
|
57
|
+
expect(start_times.size).to be 10
|
58
|
+
expect(start_times.sort.last - start_times.sort.first).to be < sleep_time * 10
|
59
|
+
end
|
60
|
+
|
34
61
|
it 'handles auto cleanup correctly' do
|
35
62
|
m = described_class.new(item)
|
36
63
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe SidekiqUniqueJobs::QueueLockTimeoutCalculator do
|
4
|
+
shared_context 'generic unscheduled job' do
|
5
|
+
subject { described_class.new('class' => 'JustAWorker') }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'public api' do
|
9
|
+
it_behaves_like 'generic unscheduled job' do
|
10
|
+
it { is_expected.to respond_to(:seconds) }
|
11
|
+
it { is_expected.to respond_to(:queue_lock_expiration) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.for_item' do
|
16
|
+
it 'initializes a new calculator' do
|
17
|
+
expect(described_class).to receive(:new).with('WAT')
|
18
|
+
described_class.for_item('WAT')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#seconds' do
|
23
|
+
subject { described_class.new(nil) }
|
24
|
+
|
25
|
+
before do
|
26
|
+
allow(subject).to receive(:time_until_scheduled).and_return(10)
|
27
|
+
allow(subject).to receive(:queue_lock_expiration).and_return(9)
|
28
|
+
end
|
29
|
+
its(:seconds) { is_expected.to eq(19) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#queue_lock_expiration' do
|
33
|
+
context 'using default unique_expiration' do
|
34
|
+
subject { described_class.new(nil) }
|
35
|
+
before { allow(subject).to receive(:worker_class_queue_lock_expiration).and_return(nil) }
|
36
|
+
|
37
|
+
its(:queue_lock_expiration) { is_expected.to eq(1_800) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'using specified sidekiq option unique_expiration' do
|
41
|
+
subject { described_class.new(nil) }
|
42
|
+
before { allow(subject).to receive(:worker_class_queue_lock_expiration).and_return(9) }
|
43
|
+
|
44
|
+
its(:queue_lock_expiration) { is_expected.to eq(9) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe SidekiqUniqueJobs::RunLockTimeoutCalculator do
|
4
|
+
shared_context 'generic unscheduled job' do
|
5
|
+
subject { described_class.new('class' => 'JustAWorker') }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'public api' do
|
9
|
+
it_behaves_like 'generic unscheduled job' do
|
10
|
+
it { is_expected.to respond_to(:seconds) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.for_item' do
|
15
|
+
it 'initializes a new calculator' do
|
16
|
+
expect(described_class).to receive(:new).with('WAT')
|
17
|
+
described_class.for_item('WAT')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#seconds' do
|
22
|
+
context 'using default run_lock_expiration' do
|
23
|
+
subject { described_class.new(nil) }
|
24
|
+
before { allow(subject).to receive(:worker_class_run_lock_expiration).and_return(9) }
|
25
|
+
|
26
|
+
its(:seconds) { is_expected.to eq(9) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'using specified sidekiq option run_lock_expiration' do
|
30
|
+
subject { described_class.new(nil) }
|
31
|
+
before { allow(subject).to receive(:worker_class_run_lock_expiration).and_return(nil) }
|
32
|
+
|
33
|
+
its(:seconds) { is_expected.to eq(60) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -12,8 +12,8 @@ RSpec.describe SidekiqUniqueJobs::TimeoutCalculator do
|
|
12
12
|
describe 'public api' do
|
13
13
|
subject { described_class.new(nil) }
|
14
14
|
it { is_expected.to respond_to(:time_until_scheduled) }
|
15
|
-
it { is_expected.to respond_to(:
|
16
|
-
it { is_expected.to respond_to(:
|
15
|
+
it { is_expected.to respond_to(:worker_class_queue_lock_expiration) }
|
16
|
+
it { is_expected.to respond_to(:worker_class_run_lock_expiration) }
|
17
17
|
it { is_expected.to respond_to(:worker_class) }
|
18
18
|
it { is_expected.to respond_to(:seconds) }
|
19
19
|
end
|
@@ -25,16 +25,6 @@ RSpec.describe SidekiqUniqueJobs::TimeoutCalculator do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#seconds' do
|
29
|
-
subject { described_class.new(nil) }
|
30
|
-
|
31
|
-
before do
|
32
|
-
allow(subject).to receive(:time_until_scheduled).and_return(10)
|
33
|
-
allow(subject).to receive(:unique_expiration).and_return(9)
|
34
|
-
end
|
35
|
-
its(:seconds) { is_expected.to eq(19) }
|
36
|
-
end
|
37
|
-
|
38
28
|
describe '#time_until_scheduled' do
|
39
29
|
it_behaves_like 'item not scheduled' do
|
40
30
|
its(:time_until_scheduled) { is_expected.to eq(0) }
|
@@ -51,22 +41,22 @@ RSpec.describe SidekiqUniqueJobs::TimeoutCalculator do
|
|
51
41
|
end
|
52
42
|
end
|
53
43
|
|
54
|
-
describe '#
|
44
|
+
describe '#worker_class_queue_lock_expiration' do
|
55
45
|
it_behaves_like 'undefined worker class' do
|
56
|
-
its(:
|
46
|
+
its(:worker_class_queue_lock_expiration) { is_expected.to eq(nil) }
|
57
47
|
end
|
58
48
|
|
59
49
|
subject { described_class.new('class' => 'MyUniqueJob') }
|
60
|
-
its(:
|
50
|
+
its(:worker_class_queue_lock_expiration) { is_expected.to eq(7_200) }
|
61
51
|
end
|
62
52
|
|
63
|
-
describe '#
|
53
|
+
describe '#worker_class_run_lock_expiration' do
|
64
54
|
it_behaves_like 'undefined worker class' do
|
65
|
-
its(:
|
55
|
+
its(:worker_class_run_lock_expiration) { is_expected.to eq(nil) }
|
66
56
|
end
|
67
57
|
|
68
|
-
subject { described_class.new('class' => '
|
69
|
-
its(:
|
58
|
+
subject { described_class.new('class' => 'LongRunningJob') }
|
59
|
+
its(:worker_class_run_lock_expiration) { is_expected.to eq(7_200) }
|
70
60
|
end
|
71
61
|
|
72
62
|
describe '#worker_class' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.
|
1
|
+
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.3.0'
|
2
2
|
if ENV['CI']
|
3
3
|
require 'codeclimate-test-reporter'
|
4
4
|
CodeClimate::TestReporter.start
|
@@ -64,69 +64,3 @@ RSpec.configure do |config|
|
|
64
64
|
end
|
65
65
|
|
66
66
|
Dir[File.join(File.dirname(__FILE__), 'jobs', '**', '*.rb')].each { |f| require f }
|
67
|
-
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.2.3'
|
68
|
-
if ENV['CI']
|
69
|
-
require 'codeclimate-test-reporter'
|
70
|
-
CodeClimate::TestReporter.start
|
71
|
-
else
|
72
|
-
require 'simplecov'
|
73
|
-
end
|
74
|
-
|
75
|
-
begin
|
76
|
-
require 'pry-byebug'
|
77
|
-
rescue LoadError
|
78
|
-
puts 'Pry unavailable'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
require 'rspec'
|
83
|
-
require 'rspec/its'
|
84
|
-
|
85
|
-
require 'celluloid_with_fallback'
|
86
|
-
require 'sidekiq'
|
87
|
-
require 'sidekiq/util'
|
88
|
-
require 'sidekiq-unique-jobs'
|
89
|
-
require 'sidekiq_unique_jobs/testing'
|
90
|
-
require 'timecop'
|
91
|
-
|
92
|
-
require 'sidekiq/simulator'
|
93
|
-
|
94
|
-
Sidekiq::Testing.disable!
|
95
|
-
Sidekiq.logger.level = "Logger::#{ENV.fetch('LOGLEVEL') { 'error' }.upcase}".constantize
|
96
|
-
|
97
|
-
require 'sidekiq/redis_connection'
|
98
|
-
|
99
|
-
begin
|
100
|
-
require 'redis-namespace'
|
101
|
-
rescue LoadError
|
102
|
-
puts 'Redis Namespace unavailable'
|
103
|
-
end
|
104
|
-
|
105
|
-
REDIS_URL ||= ENV['REDIS_URL'] || 'redis://localhost/15'.freeze
|
106
|
-
REDIS_NAMESPACE ||= 'unique-test'.freeze
|
107
|
-
REDIS_OPTIONS ||= { url: REDIS_URL }.freeze
|
108
|
-
REDIS_OPTIONS[:namespace] = REDIS_NAMESPACE if defined?(Redis::Namespace)
|
109
|
-
REDIS ||= Sidekiq::RedisConnection.create(REDIS_OPTIONS)
|
110
|
-
|
111
|
-
Sidekiq.configure_client do |config|
|
112
|
-
config.redis = REDIS_OPTIONS
|
113
|
-
end
|
114
|
-
|
115
|
-
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
|
116
|
-
RSpec.configure do |config|
|
117
|
-
config.expect_with :rspec do |expectations|
|
118
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
119
|
-
end
|
120
|
-
config.mock_with :rspec do |mocks|
|
121
|
-
mocks.verify_partial_doubles = true
|
122
|
-
end
|
123
|
-
config.filter_run :focus unless ENV['CI']
|
124
|
-
config.run_all_when_everything_filtered = true
|
125
|
-
config.disable_monkey_patching!
|
126
|
-
config.warnings = false
|
127
|
-
config.default_formatter = 'doc' if config.files_to_run.one?
|
128
|
-
config.order = :random
|
129
|
-
Kernel.srand config.seed
|
130
|
-
end
|
131
|
-
|
132
|
-
Dir[File.join(File.dirname(__FILE__), 'jobs', '**', '*.rb')].each { |f| require f }
|
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: 4.0.
|
4
|
+
version: 4.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -116,6 +116,7 @@ executables:
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
+
- ".codeclimate.yml"
|
119
120
|
- ".editorconfig"
|
120
121
|
- ".fasterer.yml"
|
121
122
|
- ".gitignore"
|
@@ -241,6 +242,7 @@ files:
|
|
241
242
|
- spec/jobs/expiring_job.rb
|
242
243
|
- spec/jobs/inline_worker.rb
|
243
244
|
- spec/jobs/just_a_worker.rb
|
245
|
+
- spec/jobs/long_running_job.rb
|
244
246
|
- spec/jobs/main_job.rb
|
245
247
|
- spec/jobs/my_job.rb
|
246
248
|
- spec/jobs/my_unique_job.rb
|
@@ -265,6 +267,8 @@ files:
|
|
265
267
|
- spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb
|
266
268
|
- spec/lib/sidekiq_unique_jobs/normalizer_spec.rb
|
267
269
|
- spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb
|
270
|
+
- spec/lib/sidekiq_unique_jobs/queue_lock_timeout_calculator_spec.rb
|
271
|
+
- spec/lib/sidekiq_unique_jobs/run_lock_timeout_calculator_spec.rb
|
268
272
|
- spec/lib/sidekiq_unique_jobs/scripts_spec.rb
|
269
273
|
- spec/lib/sidekiq_unique_jobs/server/middleware_spec.rb
|
270
274
|
- spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb
|
@@ -300,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
300
304
|
version: '0'
|
301
305
|
requirements: []
|
302
306
|
rubyforge_project:
|
303
|
-
rubygems_version: 2.5.
|
307
|
+
rubygems_version: 2.5.2
|
304
308
|
signing_key:
|
305
309
|
specification_version: 4
|
306
310
|
summary: The unique jobs that were removed from sidekiq
|