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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a49b8c44e5f5a0fb1e1c61e577d7b070a079c320
4
- data.tar.gz: 56e5652f44f26b9580634ea31a9a45c555dabf56
3
+ metadata.gz: 58ca57b1c96449ad911a8877213042e5841fed6a
4
+ data.tar.gz: ad3c813df8ea6af8fe777b5159486aef110c14ae
5
5
  SHA512:
6
- metadata.gz: ab05836a9982011714d1ab9b7d2de17d178a82c6bce9259f6921d2ae83e889cc66ee135485b8de88ce653fac18cdbb1a1e68c3ebe23c51044d0f15897775074c
7
- data.tar.gz: 2f6f2fc4ec79821e3447a41402169ff1633f36e56855f268b5de70477fe57424eb5b82a8de5b57a98e5c233c83069561e7b364b46f9df785dfc6af89d0c58c40
6
+ metadata.gz: 48b85b8f6126bc57dd6456842f55f160bdc94f0b6937197b9b03669dca4b4b67c1a22b131312439f20a485a159a3f2981ec09d4044eace8a00b4c17d044d1bfa
7
+ data.tar.gz: fcfd18f652ce9ca72db065a433401b9eb0e936700707186c53796200a2a2468a3d62aadc099ce424a14fad0972085c624d4cc8f82a45f263672a6909d756c740
@@ -1,3 +1,6 @@
1
+ ## v3.0.11
2
+ - Ensure threadsafety (thanks to adstage-david)
3
+
1
4
  ## v3.0.9
2
5
  - Fixed that all jobs stopped processing
3
6
 
data/README.md CHANGED
@@ -111,3 +111,4 @@ SidekiqUniqueJobs uses mock_redis for inline testing. Due to complaints about ha
111
111
  - https://github.com/sax
112
112
  - https://github.com/eduardosasso
113
113
  - https://github.com/KensoDev
114
+ - https://github.com/adstage-david
@@ -6,10 +6,10 @@ module SidekiqUniqueJobs
6
6
  module Connectors
7
7
  CONNECTOR_TYPES = [Testing, RedisPool, SidekiqRedis]
8
8
 
9
- def self.conn(redis_pool = nil)
9
+ def self.connection(redis_pool = nil, &block)
10
10
  CONNECTOR_TYPES.each do |connector|
11
- conn = connector.conn(redis_pool)
12
- return conn if conn
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.conn(redis_pool = nil)
4
+ def self.connection(redis_pool = nil, &block)
5
5
  return if redis_pool.nil?
6
- redis_pool.with { |conn| conn }
6
+ redis_pool.with(&block)
7
+ true
7
8
  end
8
9
  end
9
10
  end
@@ -1,8 +1,8 @@
1
1
  module SidekiqUniqueJobs
2
2
  module Connectors
3
3
  class SidekiqRedis
4
- def self.conn(_redis_pool = nil)
5
- Sidekiq.redis { |conn| conn }
4
+ def self.connection(_redis_pool = nil, &block)
5
+ Sidekiq.redis(&block)
6
6
  end
7
7
  end
8
8
  end
@@ -1,9 +1,10 @@
1
1
  module SidekiqUniqueJobs
2
2
  module Connectors
3
3
  class Testing
4
- def self.conn(_redis_pool = nil)
4
+ def self.connection(_redis_pool = nil)
5
5
  return unless SidekiqUniqueJobs.config.testing_enabled?
6
- SidekiqUniqueJobs.redis_mock { |conn| conn }
6
+ yield SidekiqUniqueJobs.redis_mock
7
+ true
7
8
  end
8
9
  end
9
10
  end
@@ -9,7 +9,6 @@ Sidekiq.configure_server do |config|
9
9
  require 'sidekiq_unique_jobs/middleware/client/unique_jobs'
10
10
  chain.add SidekiqUniqueJobs::Middleware::Client::UniqueJobs
11
11
  end
12
-
13
12
  end
14
13
 
15
14
  Sidekiq.configure_client do |config|
@@ -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.watch(payload_hash)
37
+ connection do |conn|
38
+ conn.watch(payload_hash)
37
39
 
38
- if conn.get(payload_hash).to_i == 1 ||
39
- (conn.get(payload_hash).to_i == 2 && item['at'])
40
- # if the job is already queued, or is already scheduled and
41
- # we're trying to schedule again, abort
42
- conn.unwatch
43
- else
44
- # if the job was previously scheduled and is now being queued,
45
- # or we've never seen it before
46
- expires_at = unique_job_expiration || SidekiqUniqueJobs.config.default_expiration
47
- expires_at = ((Time.at(item['at']) - Time.now.utc) + expires_at).to_i if item['at']
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
- unique = conn.multi do
50
- # set value of 2 for scheduled jobs, 1 for queued jobs.
51
- conn.setex(payload_hash, expires_at, item['at'] ? 2 : 1)
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 conn
58
- SidekiqUniqueJobs::Connectors.conn(redis_pool)
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
- conn.del(payload_hash)
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 conn
64
- SidekiqUniqueJobs::Connectors.conn(redis_pool)
63
+ def connection(&block)
64
+ SidekiqUniqueJobs::Connectors.connection(redis_pool, &block)
65
65
  end
66
66
  end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = '3.0.10'
2
+ VERSION = '3.0.11'
3
3
  end
@@ -150,7 +150,6 @@ describe 'Client' do
150
150
  expect(q2_length).to eq 0
151
151
  end
152
152
  end
153
-
154
153
  end
155
154
 
156
155
  # TODO: If anyone know of a better way to check that the expiration for scheduled
@@ -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.10
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-19 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq