sidekiq-unique-jobs 3.0.10 → 3.0.11
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/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/lib/sidekiq_unique_jobs/connectors.rb +3 -3
- data/lib/sidekiq_unique_jobs/connectors/redis_pool.rb +3 -2
- data/lib/sidekiq_unique_jobs/connectors/sidekiq_redis.rb +2 -2
- data/lib/sidekiq_unique_jobs/connectors/testing.rb +3 -2
- data/lib/sidekiq_unique_jobs/middleware.rb +0 -1
- data/lib/sidekiq_unique_jobs/middleware/client/strategies/unique.rb +20 -16
- data/lib/sidekiq_unique_jobs/middleware/server/unique_jobs.rb +3 -3
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/spec/lib/client_spec.rb +0 -1
- data/spec/lib/sidekiq_testing_enabled_spec.rb +0 -2
- data/spec/lib/sidekiq_unique_ext_spec.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58ca57b1c96449ad911a8877213042e5841fed6a
|
4
|
+
data.tar.gz: ad3c813df8ea6af8fe777b5159486aef110c14ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b85b8f6126bc57dd6456842f55f160bdc94f0b6937197b9b03669dca4b4b67c1a22b131312439f20a485a159a3f2981ec09d4044eace8a00b4c17d044d1bfa
|
7
|
+
data.tar.gz: fcfd18f652ce9ca72db065a433401b9eb0e936700707186c53796200a2a2468a3d62aadc099ce424a14fad0972085c624d4cc8f82a45f263672a6909d756c740
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -6,10 +6,10 @@ module SidekiqUniqueJobs
|
|
6
6
|
module Connectors
|
7
7
|
CONNECTOR_TYPES = [Testing, RedisPool, SidekiqRedis]
|
8
8
|
|
9
|
-
def self.
|
9
|
+
def self.connection(redis_pool = nil, &block)
|
10
10
|
CONNECTOR_TYPES.each do |connector|
|
11
|
-
|
12
|
-
return
|
11
|
+
had_connection = connector.connection(redis_pool, &block)
|
12
|
+
return if had_connection
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module SidekiqUniqueJobs
|
2
2
|
module Connectors
|
3
3
|
class RedisPool
|
4
|
-
def self.
|
4
|
+
def self.connection(redis_pool = nil, &block)
|
5
5
|
return if redis_pool.nil?
|
6
|
-
redis_pool.with
|
6
|
+
redis_pool.with(&block)
|
7
|
+
true
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module SidekiqUniqueJobs
|
2
2
|
module Connectors
|
3
3
|
class Testing
|
4
|
-
def self.
|
4
|
+
def self.connection(_redis_pool = nil)
|
5
5
|
return unless SidekiqUniqueJobs.config.testing_enabled?
|
6
|
-
SidekiqUniqueJobs.redis_mock
|
6
|
+
yield SidekiqUniqueJobs.redis_mock
|
7
|
+
true
|
7
8
|
end
|
8
9
|
end
|
9
10
|
end
|
@@ -31,31 +31,35 @@ module SidekiqUniqueJobs
|
|
31
31
|
|
32
32
|
attr_reader :item, :worker_class, :redis_pool, :queue
|
33
33
|
|
34
|
+
# rubocop:disable MethodLength
|
34
35
|
def unique_for_connection?
|
35
36
|
unique = false
|
36
|
-
conn
|
37
|
+
connection do |conn|
|
38
|
+
conn.watch(payload_hash)
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
if conn.get(payload_hash).to_i == 1 ||
|
41
|
+
(conn.get(payload_hash).to_i == 2 && item['at'])
|
42
|
+
# if the job is already queued, or is already scheduled and
|
43
|
+
# we're trying to schedule again, abort
|
44
|
+
conn.unwatch
|
45
|
+
else
|
46
|
+
# if the job was previously scheduled and is now being queued,
|
47
|
+
# or we've never seen it before
|
48
|
+
expires_at = unique_job_expiration || SidekiqUniqueJobs.config.default_expiration
|
49
|
+
expires_at = ((Time.at(item['at']) - Time.now.utc) + expires_at).to_i if item['at']
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
unique = conn.multi do
|
52
|
+
# set value of 2 for scheduled jobs, 1 for queued jobs.
|
53
|
+
conn.setex(payload_hash, expires_at, item['at'] ? 2 : 1)
|
54
|
+
end
|
52
55
|
end
|
53
56
|
end
|
54
57
|
unique
|
55
58
|
end
|
59
|
+
# rubocop:enable MethodLength
|
56
60
|
|
57
|
-
def
|
58
|
-
SidekiqUniqueJobs::Connectors.
|
61
|
+
def connection(&block)
|
62
|
+
SidekiqUniqueJobs::Connectors.connection(redis_pool, &block)
|
59
63
|
end
|
60
64
|
|
61
65
|
def payload_hash
|
@@ -53,15 +53,15 @@ module SidekiqUniqueJobs
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def unlock(payload_hash)
|
56
|
-
|
56
|
+
connection { |c| c.del(payload_hash) }
|
57
57
|
end
|
58
58
|
|
59
59
|
def logger
|
60
60
|
Sidekiq.logger
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
SidekiqUniqueJobs::Connectors.
|
63
|
+
def connection(&block)
|
64
|
+
SidekiqUniqueJobs::Connectors.connection(redis_pool, &block)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/spec/lib/client_spec.rb
CHANGED
@@ -29,7 +29,6 @@ describe 'When Sidekiq::Testing is enabled' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'with non-unique worker' do
|
32
|
-
|
33
32
|
it 'pushes duplicates messages' do
|
34
33
|
param = 'work'
|
35
34
|
expect(MyWorker.jobs.size).to eq(0)
|
@@ -120,6 +119,5 @@ describe 'When Sidekiq::Testing is enabled' do
|
|
120
119
|
expect(TestClass).to have_received(:run).with(1).twice
|
121
120
|
end
|
122
121
|
end
|
123
|
-
|
124
122
|
end
|
125
123
|
end
|
@@ -15,7 +15,6 @@ class JustAWorker
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe Sidekiq::Job::UniqueExtension do
|
18
|
-
|
19
18
|
before do
|
20
19
|
Sidekiq.redis = REDIS
|
21
20
|
Sidekiq.redis(&:flushdb)
|
@@ -35,7 +34,6 @@ describe Sidekiq::Job::UniqueExtension do
|
|
35
34
|
end
|
36
35
|
|
37
36
|
describe Sidekiq::Queue::UniqueExtension do
|
38
|
-
|
39
37
|
before do
|
40
38
|
Sidekiq.redis = REDIS
|
41
39
|
Sidekiq.redis(&:flushdb)
|
@@ -54,7 +52,6 @@ describe Sidekiq::Queue::UniqueExtension do
|
|
54
52
|
end
|
55
53
|
|
56
54
|
describe Sidekiq::JobSet::UniqueExtension, sidekiq_ver: 3 do
|
57
|
-
|
58
55
|
before do
|
59
56
|
Sidekiq.redis = REDIS
|
60
57
|
Sidekiq.redis(&:flushdb)
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|