sidekiq-unique-jobs 7.1.29 → 7.1.31

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
  SHA256:
3
- metadata.gz: cd565e57b90229451b052d1b49266df3c8e65734059119999279646ee0490939
4
- data.tar.gz: 77ea82b6eff2660b2b16f5051f4289ac9118d82c7886f339e8e32ac533ecf427
3
+ metadata.gz: a705b86a2c606801fd94c55622bc700eb52f0ca7b583aa99ded54551eef3c719
4
+ data.tar.gz: f0daa6e0f719cbaadd83e4badf66ff6d58eedfef8bb742c5bf54970ea1754653
5
5
  SHA512:
6
- metadata.gz: 3bf3b5802219d93dd64064b16f95bfa91ab1b62d12833fad575b82ff82cefd0870073b21f4a4197b0a519cbf343bdc4f60b635ca82a533b38957a76f9afb48c1
7
- data.tar.gz: ef427d3e5cb07fa6c62e422e9f8ec1116521588f8b1e6019b8c142d7b2da3ee29a12bd61aac13940a7b3f654d22bc2c8cb0f37a5ed85d19ec12deb5868fac73d
6
+ metadata.gz: d412a3f4d74a6c3ac228eb3b574ea160a0129fecd70a9d55238778c2b619a8687d3fa57efa3e6d50998363edb85b420588b1da8c50b15a08a7f0ea5986ac76f6
7
+ data.tar.gz: b2acec335a0ae5a01cb5c6f580c4c184f84d1608a85c9fd61bd5666b30cdf6d4253664146b2002cc0d6ef57d2c118dc1f5dbb86e0010723ff63a7f0716bda5b4
@@ -112,7 +112,7 @@ module SidekiqUniqueJobs
112
112
 
113
113
  def keys_for_digest(digest)
114
114
  [digest, "#{digest}:RUN"].each_with_object([]) do |key, digest_keys|
115
- digest_keys.concat([key])
115
+ digest_keys.push(key)
116
116
  digest_keys.concat(SUFFIXES.map { |suffix| "#{key}:#{suffix}" })
117
117
  end
118
118
  end
@@ -98,7 +98,7 @@ class Hash
98
98
  def _deep_transform_keys_in_object(object, &block)
99
99
  case object
100
100
  when Hash
101
- object.each_with_object({}) do |(key, value), result|
101
+ object.each_with_object(self.class.new) do |(key, value), result|
102
102
  result[yield(key)] = _deep_transform_keys_in_object(value, &block)
103
103
  end
104
104
  when Array
@@ -11,6 +11,7 @@ module SidekiqUniqueJobs
11
11
  # @return [Hash] the job hash
12
12
  def prepare(item)
13
13
  stringify_on_conflict_hash(item)
14
+ add_lock_type(item)
14
15
  add_lock_timeout(item)
15
16
  add_lock_ttl(item)
16
17
  add_digest(item)
@@ -54,5 +55,9 @@ module SidekiqUniqueJobs
54
55
  def add_lock_prefix(item)
55
56
  item[LOCK_PREFIX] ||= SidekiqUniqueJobs.config.lock_prefix
56
57
  end
58
+
59
+ def add_lock_type(item)
60
+ item[LOCK] ||= SidekiqUniqueJobs::LockType.call(item)
61
+ end
57
62
  end
58
63
  end
@@ -35,6 +35,7 @@ module SidekiqUniqueJobs
35
35
  def execute
36
36
  executed = locksmith.execute do
37
37
  yield
38
+ ensure
38
39
  unlock_and_callback
39
40
  end
40
41
 
@@ -42,9 +42,9 @@ module SidekiqUniqueJobs
42
42
  with_logging_context do
43
43
  executed = locksmith.execute do
44
44
  yield
45
- callback_safely if locksmith.unlock
45
+ item[JID]
46
46
  ensure
47
- locksmith.unlock
47
+ unlock_and_callback
48
48
  end
49
49
 
50
50
  unless executed
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqUniqueJobs
4
+ # Calculates the lock type
5
+ #
6
+ class LockType
7
+ # includes "SidekiqUniqueJobs::SidekiqWorkerMethods"
8
+ # @!parse include SidekiqUniqueJobs::SidekiqWorkerMethods
9
+ include SidekiqUniqueJobs::SidekiqWorkerMethods
10
+
11
+ #
12
+ # Computes lock type from job arguments, sidekiq_options.
13
+ #
14
+ # @return [Symbol] the lock type
15
+ # @return [NilClass] if no lock type is found.
16
+ #
17
+ def self.call(item)
18
+ new(item).call
19
+ end
20
+
21
+ # @!attribute [r] item
22
+ # @return [Hash] the Sidekiq job hash
23
+ attr_reader :item
24
+
25
+ # @param [Hash] item the Sidekiq job hash
26
+ # @option item [Symbol, nil] :lock the type of lock to use.
27
+ # @option item [String] :class the class of the sidekiq worker
28
+ def initialize(item)
29
+ @item = item
30
+ self.job_class = item[CLASS]
31
+ end
32
+
33
+ def call
34
+ item[LOCK] || job_options[LOCK] || default_job_options[LOCK]
35
+ end
36
+ end
37
+ end
@@ -127,7 +127,10 @@ module SidekiqUniqueJobs
127
127
  #
128
128
  def unlock!(conn = nil)
129
129
  call_script(:unlock, key.to_a, argv, conn) do |unlocked_jid|
130
- reflect(:debug, :unlocked, item, unlocked_jid) if unlocked_jid == job_id
130
+ if unlocked_jid == job_id
131
+ reflect(:debug, :unlocked, item, unlocked_jid)
132
+ reflect(:unlocked, item)
133
+ end
131
134
 
132
135
  unlocked_jid
133
136
  end
@@ -248,8 +251,12 @@ module SidekiqUniqueJobs
248
251
  concurrent_timeout = add_drift(timeout)
249
252
 
250
253
  reflect(:debug, :timeouts, item,
251
- timeouts: { brpoplpush_timeout: brpoplpush_timeout, concurrent_timeout: concurrent_timeout })
254
+ timeouts: {
255
+ brpoplpush_timeout: brpoplpush_timeout,
256
+ concurrent_timeout: concurrent_timeout,
257
+ })
252
258
 
259
+ # NOTE: When debugging, change .value to .value!
253
260
  primed_jid = Concurrent::Promises
254
261
  .future(conn) { |red_con| pop_queued(red_con, timeout) }
255
262
  .value
@@ -300,7 +307,10 @@ module SidekiqUniqueJobs
300
307
  def brpoplpush(conn, wait)
301
308
  # passing timeout 0 to brpoplpush causes it to block indefinitely
302
309
  raise InvalidArgument, "wait must be an integer" unless wait.is_a?(Integer)
303
- return conn.brpoplpush(key.queued, key.primed, wait) if conn.class.to_s == "Redis::Namespace"
310
+
311
+ if defined?(::Redis::Namespace) && conn.instance_of?(::Redis::Namespace)
312
+ return conn.brpoplpush(key.queued, key.primed, wait)
313
+ end
304
314
 
305
315
  if VersionCheck.satisfied?(redis_version, ">= 6.2.0") && conn.respond_to?(:blmove)
306
316
  conn.blmove(key.queued, key.primed, "RIGHT", "LEFT", timeout: wait)
@@ -15,7 +15,7 @@ local function find_digest_in_process_set(digest, threshold)
15
15
  log_debug("Found number of processes:", #processes, "next cursor:", next_process_cursor)
16
16
 
17
17
  for _, process in ipairs(processes) do
18
- local workers_key = process .. ":workers"
18
+ local workers_key = process .. ":work"
19
19
  log_debug("searching in process set:", process,
20
20
  "for digest:", digest,
21
21
  "cursor:", process_cursor)
@@ -55,7 +55,7 @@ module SidekiqUniqueJobs
55
55
  # The type of lock for this worker
56
56
  #
57
57
  #
58
- # @return [Symbol]
58
+ # @return [Symbol, NilClass]
59
59
  #
60
60
  def lock_type
61
61
  @lock_type ||= options[LOCK] || item[LOCK]
@@ -72,7 +72,7 @@ module SidekiqUniqueJobs
72
72
  # @return [<type>] <description>
73
73
  #
74
74
  def task
75
- @task ||= default_task
75
+ @task ||= default_task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
76
76
  end
77
77
 
78
78
  #
@@ -100,7 +100,7 @@ module SidekiqUniqueJobs
100
100
  # @return [void]
101
101
  #
102
102
  def task=(task)
103
- @task = task
103
+ @task = task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
104
104
  end
105
105
 
106
106
  #
@@ -195,7 +195,7 @@ module SidekiqUniqueJobs
195
195
  else
196
196
  pipeline.exists(key)
197
197
  end
198
- pipeline.hgetall("#{key}:workers")
198
+ pipeline.hgetall("#{key}:work")
199
199
  end
200
200
 
201
201
  next unless valid
@@ -54,13 +54,13 @@ module SidekiqUniqueJobs
54
54
  # Only used to reduce a little bit of duplication
55
55
  # @see call_script
56
56
  def do_call(file_name, conn, keys, argv)
57
- argv = argv.dup.concat([
58
- now_f,
59
- debug_lua,
60
- max_history,
61
- file_name,
62
- redis_version,
63
- ])
57
+ argv = argv.dup.push(
58
+ now_f,
59
+ debug_lua,
60
+ max_history,
61
+ file_name,
62
+ redis_version,
63
+ )
64
64
  Script.execute(file_name, conn, keys: keys, argv: argv)
65
65
  end
66
66
 
@@ -17,7 +17,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
17
17
  # @return [SidekiqUniqueJobs::Config] the gem configuration
18
18
  #
19
19
  def config
20
- @config ||= reset!
20
+ @config ||= reset! # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
21
21
  end
22
22
 
23
23
  #
@@ -108,7 +108,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
108
108
  # @return [SidekiqUniqueJobs::Config] a default gem configuration
109
109
  #
110
110
  def reset!
111
- @config = SidekiqUniqueJobs::Config.default
111
+ @config = SidekiqUniqueJobs::Config.default # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
112
112
  end
113
113
 
114
114
  #
@@ -288,7 +288,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
288
288
  # @return [Reflections]
289
289
  #
290
290
  def reflections
291
- @reflections ||= Reflections.new
291
+ @reflections ||= Reflections.new # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
292
292
  end
293
293
 
294
294
  #
@@ -3,5 +3,5 @@
3
3
  module SidekiqUniqueJobs
4
4
  #
5
5
  # @return [String] the current SidekiqUniqueJobs version
6
- VERSION = "7.1.29"
6
+ VERSION = "7.1.31"
7
7
  end
@@ -7,9 +7,11 @@
7
7
  <div class="col-sm-7 table-responsive">
8
8
  <% if @lock.info.none? %>
9
9
  <h3>No Lock Information Available</h3>
10
- <p>To use it turn the following setting on:
11
- <code>SidekiqUniqueJobs.config.lock_info = true</code>
12
- </p>
10
+ <% unless SidekiqUniqueJobs.config.lock_info %>
11
+ <p>To use it turn the following setting on:
12
+ <code>SidekiqUniqueJobs.config.lock_info = true</code>
13
+ </p>
14
+ <% end %>
13
15
  <% else %>
14
16
  <table class="table table-striped table-bordered table-white table-hover">
15
17
  <caption>Information about lock</caption>
@@ -27,6 +27,7 @@ require "sidekiq_unique_jobs/logging"
27
27
  require "sidekiq_unique_jobs/logging/middleware_context"
28
28
  require "sidekiq_unique_jobs/timing"
29
29
  require "sidekiq_unique_jobs/sidekiq_worker_methods"
30
+ require "sidekiq_unique_jobs/lock_type"
30
31
  require "sidekiq_unique_jobs/connection"
31
32
  require "sidekiq_unique_jobs/exceptions"
32
33
  require "sidekiq_unique_jobs/script"
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: 7.1.29
4
+ version: 7.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-03 00:00:00.000000000 Z
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brpoplpush-redis_script
@@ -151,6 +151,7 @@ files:
151
151
  - lib/sidekiq_unique_jobs/lock_info.rb
152
152
  - lib/sidekiq_unique_jobs/lock_timeout.rb
153
153
  - lib/sidekiq_unique_jobs/lock_ttl.rb
154
+ - lib/sidekiq_unique_jobs/lock_type.rb
154
155
  - lib/sidekiq_unique_jobs/locksmith.rb
155
156
  - lib/sidekiq_unique_jobs/logging.rb
156
157
  - lib/sidekiq_unique_jobs/logging/middleware_context.rb
@@ -273,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
274
  - !ruby/object:Gem::Version
274
275
  version: '0'
275
276
  requirements: []
276
- rubygems_version: 3.3.26
277
+ rubygems_version: 3.4.20
277
278
  signing_key:
278
279
  specification_version: 4
279
280
  summary: Sidekiq middleware that prevents duplicates jobs