sidekiq-unique-jobs 2.6.6 → 2.6.7

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: 2296d65fb90ede4439f99784f379eb23c75d5a1b
4
- data.tar.gz: 688b666f69e6dbd293e5662047dbe10b0429656a
3
+ metadata.gz: 83bac10875a23de22118d256945b92fff679923a
4
+ data.tar.gz: 71d378cca32301eebeb8c56bbfa1f76bdff3cd04
5
5
  SHA512:
6
- metadata.gz: bea86a75d736637326b092067172db4186dce2689d6811e48227a9e5599c391396df58e17b59f8e34c9de066cae9fafb844195dbe05a4cb23d1f177fbc780458
7
- data.tar.gz: 29b4d90da37697c917d644f062a6ac05585f6a8952da775eda22ab9bd939aae6e9f4e26196c7cf7011a0c3d848a594f3935ce25e30c54988e4a07f0ebb5cdb63
6
+ metadata.gz: 43f2b221b8a1eaa2a42a334cc263fab1e66472316eedddfa8aab18a49f9d8524691ee7f7a0dbd3168cce0a31a0877c2cf08bbad6da24228591409b3712751aab
7
+ data.tar.gz: c1fc0e67ab61a2c1def67563a0b3af418a76ff7645aa062183f2db093ddda532e852ad973cb21e5e54ad4ee54167e8862a848bae5910a89f90c02b13f6a6c33a
data/README.md CHANGED
@@ -72,6 +72,21 @@ middleware, the JSON is passed directly to the worker `#perform` method. So, you
72
72
  arguments are different when enqueuing than they are when performing. Your `unique_args` method may need to
73
73
  account for this.
74
74
 
75
+ ### Unlock Ordering
76
+
77
+ By default the server middleware will release the worker lock after yielding to the next middleware or worker. Alternatively, this can be changed by passing the `unique_unlock_order` option:
78
+
79
+ ```ruby
80
+ class UniqueJobWithFilterMethod
81
+ include Sidekiq::Worker
82
+ sidekiq_options unique: true,
83
+ unique_unlock_order: :before_yield
84
+
85
+ ...
86
+
87
+ end
88
+ ```
89
+
75
90
  ## Contributing
76
91
 
77
92
  1. Fork it
@@ -23,5 +23,13 @@ module SidekiqUniqueJobs
23
23
  def self.default_expiration
24
24
  @expiration || 30 * 60
25
25
  end
26
+
27
+ def self.default_unlock_order=(order)
28
+ @default_unlock_order = order
29
+ end
30
+
31
+ def self.default_unlock_order
32
+ @default_unlock_order || :after_yield
33
+ end
26
34
  end
27
35
  end
@@ -48,27 +48,12 @@ module SidekiqUniqueJobs
48
48
 
49
49
  # Attempt to constantize a string worker_class argument, always
50
50
  # failing back to the original argument.
51
- # Duplicates Rails' String.constantize logic for non-Rails cases.
52
51
  def worker_class_constantize(worker_class)
53
52
  if worker_class.is_a?(String)
54
- if worker_class.respond_to?(:constantize)
55
- worker_class.constantize
56
- else
57
- # duplicated logic from Rails 3.2.13 ActiveSupport::Inflector
58
- # https://github.com/rails/rails/blob/9e0b3fc7cfba43af55377488f991348e2de24515/activesupport/lib/active_support/inflector/methods.rb#L213
59
- names = worker_class.split('::')
60
- names.shift if names.empty? || names.first.empty?
61
- constant = Object
62
- names.each do |name|
63
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
64
- end
65
- constant
66
- end
53
+ worker_class.constantize rescue worker_class
67
54
  else
68
55
  worker_class
69
56
  end
70
- rescue
71
- worker_class
72
57
  end
73
58
 
74
59
  end
@@ -4,17 +4,31 @@ module SidekiqUniqueJobs
4
4
  module Middleware
5
5
  module Server
6
6
  class UniqueJobs
7
- def call(*args)
7
+ def call(worker, item, queue)
8
+ unlock_order = worker.class.get_sidekiq_options['unique_unlock_order'] ||
9
+ SidekiqUniqueJobs::Config.default_unlock_order
10
+
11
+ lock_key = payload_hash(item)
12
+
13
+ unlocked = unlock_order == :before_yield ? unlock(lock_key).inspect : 0
14
+
8
15
  yield
9
16
  ensure
10
- item = args[1]
11
- payload_hash = SidekiqUniqueJobs::PayloadHelper.get_payload(item['class'], item['queue'], item['args'])
12
-
13
- Sidekiq.redis {|conn| conn.del(payload_hash) }
17
+ if unlock_order == :after_yield || !defined? unlocked || unlocked != 1
18
+ unlock(lock_key)
19
+ end
14
20
  end
15
21
 
16
22
  protected
17
23
 
24
+ def payload_hash(item)
25
+ SidekiqUniqueJobs::PayloadHelper.get_payload(item['class'], item['queue'], item['args'])
26
+ end
27
+
28
+ def unlock(payload_hash)
29
+ Sidekiq.redis {|conn| conn.del(payload_hash) }
30
+ end
31
+
18
32
  def logger
19
33
  Sidekiq.logger
20
34
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = "2.6.6"
2
+ VERSION = "2.6.7"
3
3
  end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+ require 'sidekiq/worker'
3
+ require 'sidekiq-unique-jobs/middleware/server/unique_jobs'
4
+
5
+ class TestUnlockOrdering < MiniTest::Unit::TestCase
6
+ QUEUE = 'unlock_ordering'
7
+
8
+ class BeforeYieldOrderingWorker
9
+ include Sidekiq::Worker
10
+
11
+ sidekiq_options unique: true, unique_unlock_order: :before_yield, queue: QUEUE
12
+
13
+ def perform
14
+ end
15
+ end
16
+
17
+ class AfterYieldOrderingWorker
18
+ include Sidekiq::Worker
19
+
20
+ sidekiq_options unique: true, unique_unlock_order: :after_yield, queue: QUEUE
21
+
22
+ def perform
23
+ end
24
+ end
25
+
26
+ describe 'with real redis' do
27
+ before do
28
+ Sidekiq.redis = REDIS
29
+ Sidekiq.redis { |c| c.flushdb }
30
+ @middleware = SidekiqUniqueJobs::Middleware::Server::UniqueJobs.new
31
+ end
32
+
33
+ describe ':before_yield' do
34
+ it 'removes the lock before yielding to the worker' do
35
+ jid = BeforeYieldOrderingWorker.perform_async
36
+ item = Sidekiq::Queue.new(QUEUE).find_job(jid).item
37
+
38
+ result = @middleware.call(BeforeYieldOrderingWorker.new, item, QUEUE) do
39
+ Sidekiq.redis do |c|
40
+ c.get(SidekiqUniqueJobs::PayloadHelper.get_payload(item['class'], item['queue'], item['args']))
41
+ end
42
+ end
43
+
44
+ assert_nil result
45
+ end
46
+ end
47
+
48
+ describe ':after_yield' do
49
+ it 'removes the lock after yielding to the worker' do
50
+ jid = AfterYieldOrderingWorker.perform_async
51
+ item = Sidekiq::Queue.new(QUEUE).find_job(jid).item
52
+
53
+ result = @middleware.call(AfterYieldOrderingWorker.new, item, QUEUE) do
54
+ Sidekiq.redis do |c|
55
+ c.get(SidekiqUniqueJobs::PayloadHelper.get_payload(item['class'], item['queue'], item['args']))
56
+ end
57
+ end
58
+
59
+ assert_equal '1', result
60
+ end
61
+ end
62
+ end
63
+ end
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: 2.6.6
4
+ version: 2.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-23 00:00:00.000000000 Z
11
+ date: 2013-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -133,6 +133,7 @@ files:
133
133
  - test/helper.rb
134
134
  - test/lib/sidekiq/another_test_client.rb
135
135
  - test/lib/sidekiq/test_client.rb
136
+ - test/lib/sidekiq/test_unlock_ordering.rb
136
137
  homepage: http://mperham.github.com/sidekiq
137
138
  licenses:
138
139
  - LGPL-3.0
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.0.3
157
+ rubygems_version: 2.0.7
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: The unique jobs that were removed from sidekiq
@@ -161,4 +162,5 @@ test_files:
161
162
  - test/helper.rb
162
163
  - test/lib/sidekiq/another_test_client.rb
163
164
  - test/lib/sidekiq/test_client.rb
165
+ - test/lib/sidekiq/test_unlock_ordering.rb
164
166
  has_rdoc: