sidekiq-unique-jobs 4.0.12 → 4.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sidekiq-unique-jobs might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/bin/bench +19 -0
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +17 -7
- data/lib/sidekiq_unique_jobs/unlockable.rb +1 -1
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/redis/aquire_lock.lua +1 -1
- data/redis/release_lock.lua +5 -2
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +2 -2
- data/spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb +32 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a667c02accea5b2f80e5ba1b193386a416d15453
|
4
|
+
data.tar.gz: c8e813d81b96efc50d1870d32e7c9b3e257ffb63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30cf3f31dee1a248da9541e8fa7fc4f775f7082919b7baba93c89d013a62fef10450dd882ed726ed1c4af98962ee9995a2df58e8549f5270464b48b51dcb9545
|
7
|
+
data.tar.gz: d18f162f26b71b9a1ab2b8e865ad8da609ea43e993306f46714e7bd289aaea883724a2a2e72e65611fd22aaab4e5ad3d01673b4b412439339cfa9cda53c9221d
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/bin/bench
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Trap interrupts to quit cleanly. See
|
4
|
+
# https://twitter.com/mitchellh/status/283014103189053442
|
5
|
+
Signal.trap('INT') { abort }
|
6
|
+
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'benchmark/ips'
|
9
|
+
require 'sidekiq-unique-jobs'
|
10
|
+
|
11
|
+
ITERATIONS ||= 10_000
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
x.config(time: 5, warmup: 2)
|
15
|
+
x.report('new_shit') do |_times|
|
16
|
+
SidekiqUniqueJobs::Scripts.call(:aquire_lock, nil, keys: [SecureRandom.hex], argv: [SecureRandom.hex])
|
17
|
+
end
|
18
|
+
x.compare!
|
19
|
+
end
|
@@ -26,13 +26,23 @@ module SidekiqUniqueJobs
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def unique_lock
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
@unique_lock ||=
|
30
|
+
if options.key?(UNIQUE_KEY) && options[UNIQUE_KEY].to_s == 'true'
|
31
|
+
warn('unique: true is no longer valid. Please set it to the type of lock required like: ' \
|
32
|
+
'`unique: :until_executed`')
|
33
|
+
options[UNIQUE_LOCK_KEY] || SidekiqUniqueJobs.default_lock
|
34
|
+
else
|
35
|
+
lock_type || SidekiqUniqueJobs.default_lock
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def lock_type
|
40
|
+
lock_type_from(options) || lock_type_from(item)
|
41
|
+
end
|
42
|
+
|
43
|
+
def lock_type_from(hash, key = UNIQUE_KEY)
|
44
|
+
return nil if hash[key].is_a?(TrueClass)
|
45
|
+
hash[key]
|
36
46
|
end
|
37
47
|
|
38
48
|
def options
|
@@ -13,7 +13,7 @@ module SidekiqUniqueJobs
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def unlock_by_jid(jid, redis_pool = nil)
|
16
|
-
Scripts.call(:
|
16
|
+
Scripts.call(:release_lock_by_jid, redis_pool, keys: [jid]) do |result|
|
17
17
|
after_unlock(result, __method__)
|
18
18
|
end
|
19
19
|
end
|
data/redis/aquire_lock.lua
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
local unique_key = KEYS[1]
|
2
2
|
local job_id = ARGV[1]
|
3
3
|
local expires = ARGV[2]
|
4
|
-
local scheduled = ARGV[3]
|
5
4
|
local stored_jid = redis.pcall('get', unique_key)
|
6
5
|
|
7
6
|
if stored_jid then
|
@@ -13,6 +12,7 @@ if stored_jid then
|
|
13
12
|
end
|
14
13
|
|
15
14
|
if redis.pcall('set', unique_key, job_id, 'nx', 'ex', expires) then
|
15
|
+
redis.pcall('hsetnx', 'uniquejobs', job_id, unique_key)
|
16
16
|
return 1
|
17
17
|
else
|
18
18
|
return 0
|
data/redis/release_lock.lua
CHANGED
@@ -3,8 +3,11 @@ local job_id = ARGV[1]
|
|
3
3
|
local stored_jid = redis.pcall('get', unique_key)
|
4
4
|
|
5
5
|
if stored_jid then
|
6
|
-
if stored_jid == job_id then
|
7
|
-
|
6
|
+
if stored_jid == job_id or stored_jid == '2' then
|
7
|
+
if redis.pcall('del', unique_key) then
|
8
|
+
redis.pcall('hdel', 'uniquejobs', job_id)
|
9
|
+
return 1
|
10
|
+
end
|
8
11
|
else
|
9
12
|
return 0
|
10
13
|
end
|
@@ -15,14 +15,14 @@ RSpec.describe SidekiqUniqueJobs::Client::Middleware do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'when a job is already scheduled' do
|
18
|
-
|
19
18
|
it 'processes jobs properly', sidekiq_ver: '>= 4.0.0' do
|
20
19
|
Sidekiq::Testing.disable! do
|
21
20
|
jid = NotifyWorker.perform_in(1, 183, 'xxxx')
|
22
21
|
expect(jid).not_to eq(nil)
|
23
22
|
Sidekiq.redis do |c|
|
24
23
|
expect(c.zcard('schedule')).to eq(1)
|
25
|
-
|
24
|
+
expected = %w(schedule uniquejobs:6e47d668ad22db2a3ba0afd331514ce2 uniquejobs)
|
25
|
+
expect(c.keys).to match_array(expected)
|
26
26
|
end
|
27
27
|
sleep 1
|
28
28
|
Sidekiq::Scheduled::Enq.new.enqueue_jobs
|
@@ -39,6 +39,12 @@ RSpec.describe SidekiqUniqueJobs::OptionsWithFallback do
|
|
39
39
|
let(:options) { {} }
|
40
40
|
let(:item) { { 'unique' => 'until_executed' } }
|
41
41
|
its(:unique_enabled?) { is_expected.to eq('until_executed') }
|
42
|
+
|
43
|
+
context 'when true' do
|
44
|
+
let(:options) { {} }
|
45
|
+
let(:item) { { 'unique' => true } }
|
46
|
+
its(:unique_enabled?) { is_expected.to eq(true) }
|
47
|
+
end
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
@@ -60,6 +66,32 @@ RSpec.describe SidekiqUniqueJobs::OptionsWithFallback do
|
|
60
66
|
end
|
61
67
|
end
|
62
68
|
|
69
|
+
describe '#lock_type' do
|
70
|
+
context 'when options["unique"] is while_executing' do
|
71
|
+
let(:options) { { 'unique' => 'while_executing' } }
|
72
|
+
let(:item) { { 'unique' => 'until_executed' } }
|
73
|
+
its(:lock_type) { is_expected.to eq('while_executing') }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when options["unique"] is true' do
|
77
|
+
let(:options) { { 'unique' => true } }
|
78
|
+
let(:item) { { 'unique' => 'until_executed' } }
|
79
|
+
its(:lock_type) { is_expected.to eq('until_executed') }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when item["unique"] is until_executed' do
|
83
|
+
let(:options) { {} }
|
84
|
+
let(:item) { { 'unique' => 'until_executed' } }
|
85
|
+
its(:lock_type) { is_expected.to eq('until_executed') }
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when item["unique"] is true' do
|
89
|
+
let(:options) { { 'unique' => true } }
|
90
|
+
let(:item) { { 'unique' => true } }
|
91
|
+
its(:lock_type) { is_expected.to eq(nil) }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
63
95
|
describe '#options' do
|
64
96
|
context 'when worker_class respond_to get_sidekiq_options' do
|
65
97
|
let(:worker_class) { SimpleWorker }
|
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.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-12-
|
11
|
+
date: 2015-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- LICENSE
|
130
130
|
- README.md
|
131
131
|
- Rakefile
|
132
|
+
- bin/bench
|
132
133
|
- bin/jobs
|
133
134
|
- circle.yml
|
134
135
|
- gemfiles/sidekiq_2.15.gemfile
|