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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ad145a74f603f0fb35ab336670b69de2f4d15f5
4
- data.tar.gz: a3f37457af73e6256eb1dbcfa5f6a5ac36c4d0b7
3
+ metadata.gz: a667c02accea5b2f80e5ba1b193386a416d15453
4
+ data.tar.gz: c8e813d81b96efc50d1870d32e7c9b3e257ffb63
5
5
  SHA512:
6
- metadata.gz: ae02108f28fef4e4270b0b37c836191214b18c9e47b34ba5f7a6c0e748f7bf1c9cff5a9f4e9c9fde5deac0163b4e541eb127fe8f05cc2b68ef932e8ae79c3d57
7
- data.tar.gz: 1e107f3d113d99d6e9e0c11e8f98718c782bfd7141a6b613eb2b295e1fb64caa205d97aeaf606b245bb9c0bf6cf42791330f22404ef9de9cbffb5bd560acc647
6
+ metadata.gz: 30cf3f31dee1a248da9541e8fa7fc4f775f7082919b7baba93c89d013a62fef10450dd882ed726ed1c4af98962ee9995a2df58e8549f5270464b48b51dcb9545
7
+ data.tar.gz: d18f162f26b71b9a1ab2b8e865ad8da609ea43e993306f46714e7bd289aaea883724a2a2e72e65611fd22aaab4e5ad3d01673b4b412439339cfa9cda53c9221d
@@ -32,3 +32,6 @@ matrix:
32
32
  - rvm: 2.2.3
33
33
  gemfile: gemfiles/sidekiq_develop.gemfile
34
34
  env: STYLE=true
35
+ addons:
36
+ code_climate:
37
+ repo_token: 88e524e8f638efe690def7a6e2c72b1a9db5cdfa74548921b734d609a5858ee5
@@ -1,3 +1,7 @@
1
+ ## v4.0.13
2
+
3
+ - Allow deleting locks by jid
4
+
1
5
  ## v4.0.12
2
6
 
3
7
  - Allow jobs to be pushed to processing
@@ -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
- if options.key?(UNIQUE_KEY) && options[UNIQUE_KEY] == true
30
- warn('unique: true is no longer valid. Please set it to the type of lock required like: ' \
31
- '`unique: :until_executed`')
32
- options[UNIQUE_LOCK_KEY] || SidekiqUniqueJobs.default_lock
33
- else
34
- options[UNIQUE_KEY] || item[UNIQUE_KEY] || SidekiqUniqueJobs.default_lock
35
- end
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(:release_lock, redis_pool, keys: [unique_key], argv: [jid]) do |result|
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
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = '4.0.12'
2
+ VERSION = '4.0.13'
3
3
  end
@@ -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
@@ -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
- return redis.pcall('del', unique_key)
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
- expect(c.keys).to match_array(%w(schedule uniquejobs:6e47d668ad22db2a3ba0afd331514ce2))
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.12
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-15 00:00:00.000000000 Z
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