sidekiq-unique-jobs 8.0.3 → 8.0.5

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: 2462acb2448a07c45eb8a1789239f859a09e079cff316fe61dc205d9ea8856a4
4
- data.tar.gz: 57449a594cd034c79001815883806098e04a92869c41cbe6044c90ab6f1fa3ae
3
+ metadata.gz: 1573748a7de5be552d85b9e74143425fd99b2e85e4e6be1ccdbbd8ba9ecc0f37
4
+ data.tar.gz: 520fe1d492c9e088df5b6dc138d8bc4024516486c216e8223fe0f55462cfe691
5
5
  SHA512:
6
- metadata.gz: b200d3544047b6080147b19b71ffd83a0ac42087ed29f1d84fb35b226b1418f50e37c94b309a946504c32d26b11b5fd173ade85e77c568931d33b948f1c656f9
7
- data.tar.gz: 9d12cbf3317acd4e5bd6d934616622e5ac3336ecba4e51b2b29fbf6782deab2b1af291af1471e16da7271fef42b33804b7a3c7f3475016de88bd75e2d0668684
6
+ metadata.gz: 23542e9860f30b16f14c1907790e1bd491e98524dad73b726b88592b8e0cbcf06fa4b535837fc534e4ccf4a80d619840bdf7ec01c3104e3053f1ec5661ea92d5
7
+ data.tar.gz: d61c18630ab31064bac8ed9fad52fc84a08ad9bc384ac39d9ed8a44e6e4b741aafa0ebd2845a9f465da8e811e634dab0a8f92ee768c9bb19f9ba8cdb64b10190
data/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
1
  # Changelog
2
2
 
3
+ ## [v8.0.4](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.4) (2023-11-11)
4
+
5
+ [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.30...v8.0.4)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - fix: ignore reek for now [\#818](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/818) ([mhenrixon](https://github.com/mhenrixon))
10
+ - fix\(ci\): allow tests to run in docker [\#805](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/805) ([Earlopain](https://github.com/Earlopain))
11
+ - chore\(deps\): bump'n lint'n such [\#797](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/797) ([mhenrixon](https://github.com/mhenrixon))
12
+
13
+ **Fixed bugs:**
14
+
15
+ - Sidekiq 7: Unsupported command argument type: TrueClass [\#816](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/816)
16
+ - fix\(web\): don't show bogus lock digests [\#804](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/804) ([Earlopain](https://github.com/Earlopain))
17
+
18
+ **Closed issues:**
19
+
20
+ - register\_reaper\_process nx: true crash Sidekiq on startup [\#817](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/817)
21
+ - Should client middleware also be added to the Sidekiq server config? [\#803](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/803)
22
+ - 8.0.1 Time on locks & changelog UI is incorrect/wrong [\#761](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/761)
23
+ - Job executed twice when reaper runs [\#738](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/738)
24
+
25
+ **Merged pull requests:**
26
+
27
+ - fix: Sidekiq 7.2 throws TypeError: Unsupported command argument type: TrueClass when using byscore: true [\#815](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/815) ([Amnesthesia](https://github.com/Amnesthesia))
28
+ - Add sidekiq\_option for on-conflict-reschedule perform\_in time [\#813](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/813) ([mgmarlow](https://github.com/mgmarlow))
29
+ - Handle strategy fallbacks properly [\#809](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/809) ([matejrisek](https://github.com/matejrisek))
30
+ - Fix CI status badge [\#802](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/802) ([tagliala](https://github.com/tagliala))
31
+
32
+ ## [v7.1.30](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.30) (2023-07-17)
33
+
34
+ [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.3...v7.1.30)
35
+
36
+ **Closed issues:**
37
+
38
+ - Release new gem version with "fix replace deprecated rpoplpush w/lmove" [\#795](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/795)
39
+ - Redis has deprecated the `rpoplpush`command [\#793](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/793)
40
+ - Deprecation Warning: Use of rpoplpush command in Redis [\#792](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/792)
41
+ - Logging::Middleware.context can include empty string as key when lock is not set in job hash [\#785](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/785)
42
+
43
+ ## [v8.0.3](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.3) (2023-05-27)
44
+
45
+ [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.2...v8.0.3)
46
+
47
+ **Implemented enhancements:**
48
+
49
+ - chore\(ci\): improve matrix [\#775](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/775) ([mhenrixon](https://github.com/mhenrixon))
50
+ - chore\(ci\): better ci job output [\#772](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/772) ([mhenrixon](https://github.com/mhenrixon))
51
+
52
+ **Fixed bugs:**
53
+
54
+ - Add unlocked reflect to locksmith unlock! [\#783](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/783) ([ttstarck](https://github.com/ttstarck))
55
+ - fix\(locksmith\): replace deprecated rpoplpush w/lmove [\#781](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/781) ([GabrielaGuedes](https://github.com/GabrielaGuedes))
56
+ - fix\(unlock\): ensure callback and unlock [\#771](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/771) ([mhenrixon](https://github.com/mhenrixon))
57
+
58
+ **Closed issues:**
59
+
60
+ - `unlocked` reflection is never called [\#782](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/782)
61
+ - Migrate away from deprecated Redis commands [\#780](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/780)
62
+ - `while_executing` with `on_conflict: :reschedule` reschedules job when unlock fails [\#770](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/770)
63
+ - Redis server v6.0 compatibility [\#769](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/769)
64
+ - Locks not removed after worker finishes [\#758](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/758)
65
+
66
+ **Merged pull requests:**
67
+
68
+ - Add lock to item when lock\_type is pulled from Job class sidekiq options [\#786](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/786) ([ttstarck](https://github.com/ttstarck))
69
+ - Fix rubocop failure by expecting array to be empty [\#784](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/784) ([GabrielaGuedes](https://github.com/GabrielaGuedes))
70
+ - fix\(doc\): improve information on unlock\_failed [\#776](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/776) ([mhenrixon](https://github.com/mhenrixon))
71
+
3
72
  ## [v8.0.2](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.2) (2023-03-13)
4
73
 
5
74
  [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.1...v8.0.2)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SidekiqUniqueJobs
2
2
 
3
- [![Join the chat at https://gitter.im/mhenrixon/sidekiq-unique-jobs](https://badges.gitter.im/mhenrixon/sidekiq-unique-jobs.svg)](https://gitter.im/mhenrixon/sidekiq-unique-jobs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Build Status](https://github.com/mhenrixon/sidekiq-unique-jobs/actions/workflows/rspec.yml/badge.svg?branch=master) [![Code Climate](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs) [![Test Coverage](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/badges/coverage.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/coverage)
3
+ [![Join the chat at https://gitter.im/mhenrixon/sidekiq-unique-jobs](https://badges.gitter.im/mhenrixon/sidekiq-unique-jobs.svg)](https://gitter.im/mhenrixon/sidekiq-unique-jobs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Build Status](https://github.com/mhenrixon/sidekiq-unique-jobs/actions/workflows/rspec.yml/badge.svg?branch=main) [![Code Climate](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs) [![Test Coverage](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/badges/coverage.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/coverage)
4
4
 
5
5
  ## Support Me
6
6
 
@@ -7,6 +7,16 @@ module SidekiqUniqueJobs
7
7
  # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  #
9
9
  class Digests < Redis::SortedSet
10
+ #
11
+ # @return [Integer] the number of matches to return by default
12
+ DEFAULT_COUNT = 1_000
13
+ #
14
+ # @return [String] the default pattern to use for matching
15
+ SCAN_PATTERN = "*"
16
+ #
17
+ # @return [Array(String, String, String, String)] The empty runtime or queuetime keys.
18
+ EMPTY_KEYS_SEGMENT = ["", "", "", ""].freeze
19
+
10
20
  def initialize(digests_key = DIGESTS)
11
21
  super(digests_key)
12
22
  end
@@ -41,19 +51,14 @@ module SidekiqUniqueJobs
41
51
  # Also deletes the :AVAILABLE, :EXPIRED etc keys
42
52
  #
43
53
  # @param [String] digest a unique digest to delete
44
- def delete_by_digest(digest) # rubocop:disable Metrics/MethodLength
54
+ # @param queuetime [Boolean] Whether to delete queue locks.
55
+ # @param runtime [Boolean] Whether to delete run locks.
56
+ def delete_by_digest(digest, queuetime: true, runtime: true)
45
57
  result, elapsed = timed do
46
- call_script(:delete_by_digest, [
47
- digest,
48
- "#{digest}:QUEUED",
49
- "#{digest}:PRIMED",
50
- "#{digest}:LOCKED",
51
- "#{digest}:RUN",
52
- "#{digest}:RUN:QUEUED",
53
- "#{digest}:RUN:PRIMED",
54
- "#{digest}:RUN:LOCKED",
55
- key,
56
- ])
58
+ call_script(
59
+ :delete_by_digest,
60
+ queuetime_keys(queuetime ? digest : nil) + runtime_keys(runtime ? digest : nil) + [key],
61
+ )
57
62
  end
58
63
 
59
64
  log_info("#{__method__}(#{digest}) completed in #{elapsed}ms")
@@ -93,9 +98,37 @@ module SidekiqUniqueJobs
93
98
  [
94
99
  total_size.to_i,
95
100
  digests[0].to_i, # next_cursor
96
- digests[1].map { |digest, score| Lock.new(digest, time: score) }, # entries
101
+ digests[1].each_slice(2).map { |digest, score| Lock.new(digest, time: score) }, # entries
97
102
  ]
98
103
  end
99
104
  end
105
+
106
+ private
107
+
108
+ # @param digest [String, nil] The digest to form runtime keys from.
109
+ # @return [Array(String, String, String, String)] The list of runtime keys or empty strings if +digest+ was +nil+.
110
+ def runtime_keys(digest)
111
+ return EMPTY_KEYS_SEGMENT unless digest
112
+
113
+ [
114
+ "#{digest}:RUN",
115
+ "#{digest}:RUN:QUEUED",
116
+ "#{digest}:RUN:PRIMED",
117
+ "#{digest}:RUN:LOCKED",
118
+ ]
119
+ end
120
+
121
+ # @param digest [String, nil] The digest to form queuetime keys from.
122
+ # @return [Array(String, String, String, String)] The list of queuetime keys or empty strings if +digest+ was +nil+.
123
+ def queuetime_keys(digest)
124
+ return EMPTY_KEYS_SEGMENT unless digest
125
+
126
+ [
127
+ digest,
128
+ "#{digest}:QUEUED",
129
+ "#{digest}:PRIMED",
130
+ "#{digest}:LOCKED",
131
+ ]
132
+ end
100
133
  end
101
134
  end
@@ -42,6 +42,7 @@ module SidekiqUniqueJobs
42
42
  with_logging_context do
43
43
  executed = locksmith.execute do
44
44
  yield
45
+ item[JID]
45
46
  ensure
46
47
  unlock_and_callback
47
48
  end
@@ -47,7 +47,7 @@ module SidekiqUniqueJobs
47
47
  #
48
48
  def initialize(key, time: nil)
49
49
  @key = get_key(key)
50
- time = time.is_a?(Float) ? time : time.to_f
50
+ time = time.to_f unless time.is_a?(Float)
51
51
  return unless time.nonzero?
52
52
 
53
53
  @created_at = time
@@ -113,14 +113,20 @@ module SidekiqUniqueJobs
113
113
 
114
114
  # the strategy to use as conflict resolution from sidekiq client
115
115
  def on_client_conflict
116
- @on_client_conflict ||= on_conflict["client"] || on_conflict[:client] if on_conflict.is_a?(Hash)
117
- @on_client_conflict ||= on_conflict
116
+ @on_client_conflict ||= if on_conflict.is_a?(Hash)
117
+ on_conflict["client"] || on_conflict[:client]
118
+ else
119
+ on_conflict
120
+ end
118
121
  end
119
122
 
120
123
  # the strategy to use as conflict resolution from sidekiq server
121
124
  def on_server_conflict
122
- @on_server_conflict ||= on_conflict["server"] || on_conflict[:server] if on_conflict.is_a?(Hash)
123
- @on_server_conflict ||= on_conflict
125
+ @on_server_conflict ||= if on_conflict.is_a?(Hash)
126
+ on_conflict["server"] || on_conflict[:server]
127
+ else
128
+ on_conflict
129
+ end
124
130
  end
125
131
  end
126
132
  end
@@ -65,7 +65,7 @@ module SidekiqUniqueJobs
65
65
  # @return [Integer] the number of keys deleted
66
66
  #
67
67
  def delete_lock
68
- digests.delete_by_digest(lock_digest)
68
+ digests.delete_by_digest(lock_digest, runtime: false)
69
69
  end
70
70
 
71
71
  #
@@ -21,7 +21,7 @@ module SidekiqUniqueJobs
21
21
  # This will mess up sidekiq stats because a new job is created
22
22
  def call
23
23
  if sidekiq_job_class?
24
- if job_class.set(queue: item["queue"].to_sym).perform_in(5, *item[ARGS])
24
+ if job_class.set(queue: item["queue"].to_sym).perform_in(schedule_in, *item[ARGS])
25
25
  reflect(:rescheduled, item)
26
26
  else
27
27
  reflect(:reschedule_failed, item)
@@ -30,6 +30,10 @@ module SidekiqUniqueJobs
30
30
  reflect(:unknown_sidekiq_worker, item)
31
31
  end
32
32
  end
33
+
34
+ def schedule_in
35
+ job_class.get_sidekiq_options["schedule_in"] || 5
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -192,7 +192,7 @@ module SidekiqUniqueJobs
192
192
  # @return [void]
193
193
  #
194
194
  def register_reaper_process
195
- redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, nx: true, ex: drift_reaper_interval) }
195
+ redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "nx", "ex", drift_reaper_interval) }
196
196
  end
197
197
 
198
198
  #
@@ -202,7 +202,7 @@ module SidekiqUniqueJobs
202
202
  # @return [void]
203
203
  #
204
204
  def refresh_reaper_mutex
205
- redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, ex: drift_reaper_interval) }
205
+ redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "ex", drift_reaper_interval) }
206
206
  end
207
207
 
208
208
  #
@@ -79,7 +79,7 @@ module SidekiqUniqueJobs
79
79
  def expired_digests
80
80
  max_score = (start_time - reaper_timeout).to_f
81
81
 
82
- conn.zrange(EXPIRING_DIGESTS, 0, max_score, byscore: true)
82
+ conn.zrange(EXPIRING_DIGESTS, 0, max_score, "byscore")
83
83
  end
84
84
 
85
85
  #
@@ -24,10 +24,11 @@ module SidekiqUniqueJobs
24
24
  # @return [Hash] when given with_scores: true
25
25
  #
26
26
  def entries(with_scores: true)
27
- entrys = redis { |conn| conn.zrange(key, 0, -1, withscores: with_scores) }
28
- return entrys unless with_scores
27
+ return redis { |conn| conn.zrange(key, 0, -1) } unless with_scores
29
28
 
30
- entrys.each_with_object({}) { |pair, hash| hash[pair[0]] = pair[1] }
29
+ redis { |conn| conn.zrange(key, 0, -1, "withscores") }.each_with_object({}) do |pair, hash|
30
+ hash[pair[0]] = pair[1]
31
+ end
31
32
  end
32
33
 
33
34
  #
@@ -3,5 +3,5 @@
3
3
  module SidekiqUniqueJobs
4
4
  #
5
5
  # @return [String] the current SidekiqUniqueJobs version
6
- VERSION = "8.0.3"
6
+ VERSION = "8.0.5"
7
7
  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: 8.0.3
4
+ version: 8.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-10 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
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  requirements: []
237
- rubygems_version: 3.4.15
237
+ rubygems_version: 3.4.20
238
238
  signing_key:
239
239
  specification_version: 4
240
240
  summary: Sidekiq middleware that prevents duplicates jobs