sidekiq-unique-jobs 7.0.0.beta23 → 7.0.0.beta24

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: 85f40cdbdf1f6652712a0a5ef535a58cb4831a871b0defa73b5b32db54bb8a02
4
- data.tar.gz: 4ed0cc541f98f80f6875d6e47b077494d623f72d40392e201977d0510b0cb18b
3
+ metadata.gz: cbd7bb8a58fe7319fb013de48e8c3914bb66157bb447b7186adaa9e936d1975e
4
+ data.tar.gz: 79e21055189827adeb3e8dadffe4ad86b75c464e5261731532e599278c3a154e
5
5
  SHA512:
6
- metadata.gz: b6a43eb07c5bc25ae1b40a521f56280eb37dec346ada147d07f1eae5a125bc4e29455548987796d52ab8bea16c7587c4a5e08a57dfa9cfb4fba47b0d2f152799
7
- data.tar.gz: 998560f4beadb2d2e3012b44d5f1d792e1b42ba18881f3f6b699d8486ad5593923469d755eb473c023d107c311014e51b1400ed772f5138ba4010104ba29c88d
6
+ metadata.gz: 83bdc216d7b13aefc6cb168a175e6fda8974ae9fbbe356505889b20f1ed358b297d4fbe1fd8cb67ad5e393a332db764b81d58a9978508fd7cfe6ce0b83f49ff3
7
+ data.tar.gz: ea3b0d0681a700f434b4204ddad09374b22375365c4bf7532a5a56fe70b9e08d1a4a6bcc38dfae2f91efb60d00553a13c942e0737b5fb1b1fc0124f38c1f9c2b
data/README.md CHANGED
@@ -562,17 +562,22 @@ If you need to perform any additional work after the lock has been released you
562
562
  **Exception 1:** UntilExecuting unlocks and uses callback before yielding.
563
563
  **Exception 2:** UntilExpired expires eventually, no after_unlock hook is called.
564
564
 
565
+ **NOTE:** _It is also possible to write this code as a class method._
566
+
565
567
  ```ruby
566
568
  class UniqueJobWithFilterMethod
567
569
  include Sidekiq::Worker
568
570
  sidekiq_options lock: :while_executing,
569
571
 
572
+ def self.after_unlock
573
+ # block has yielded and lock is released
574
+ end
575
+
570
576
  def after_unlock
571
577
  # block has yielded and lock is released
572
578
  end
573
579
  ...
574
580
  end.
575
- ```
576
581
 
577
582
  ### Logging
578
583
 
@@ -26,7 +26,6 @@ require "sidekiq_unique_jobs/connection"
26
26
  require "sidekiq_unique_jobs/exceptions"
27
27
  require "sidekiq_unique_jobs/script"
28
28
  require "sidekiq_unique_jobs/script/caller"
29
- require "sidekiq_unique_jobs/json"
30
29
  require "sidekiq_unique_jobs/normalizer"
31
30
  require "sidekiq_unique_jobs/job"
32
31
  require "sidekiq_unique_jobs/redis"
@@ -10,7 +10,7 @@ module SidekiqUniqueJobs
10
10
  #
11
11
  class Cli < Thor
12
12
  # :nodoc:
13
- def self.banner(command, _namespace = nil, _subcommand = false)
13
+ def self.banner(command, _namespace = nil, _subcommand = false) # rubocop:disable Style/OptionalBooleanParameter
14
14
  "jobs #{@package_name} #{command.usage}" # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
15
15
  end
16
16
 
@@ -97,7 +97,7 @@ module SidekiqUniqueJobs
97
97
  end
98
98
 
99
99
  # The method to use for filtering unique arguments
100
- def lock_args_method
100
+ def lock_args_method # rubocop:disable Metrics/CyclomaticComplexity
101
101
  @lock_args_method ||= worker_options[LOCK_ARGS] || worker_options[UNIQUE_ARGS]
102
102
  @lock_args_method ||= :lock_args if worker_method_defined?(:lock_args)
103
103
  @lock_args_method ||= :unique_args if worker_method_defined?(:unique_args)
@@ -59,12 +59,12 @@ module SidekiqUniqueJobs
59
59
  def initialize(job_hash = {})
60
60
  @type = job_hash[LOCK]&.to_sym
61
61
  @worker = job_hash[CLASS]
62
- @limit = job_hash.fetch(LOCK_LIMIT) { 1 }
63
- @timeout = job_hash.fetch(LOCK_TIMEOUT) { 0 }
64
- @ttl = job_hash.fetch(LOCK_TTL) { job_hash.fetch(LOCK_EXPIRATION) { nil } }.to_i
62
+ @limit = job_hash.fetch(LOCK_LIMIT, 1)
63
+ @timeout = job_hash.fetch(LOCK_TIMEOUT, 0)
64
+ @ttl = job_hash.fetch(LOCK_TTL) { job_hash.fetch(LOCK_EXPIRATION, nil) }.to_i
65
65
  @pttl = ttl * 1_000
66
66
  @lock_info = job_hash.fetch(LOCK_INFO) { SidekiqUniqueJobs.config.lock_info }
67
- @on_conflict = job_hash.fetch(ON_CONFLICT) { nil }
67
+ @on_conflict = job_hash.fetch(ON_CONFLICT, nil)
68
68
  @errors = job_hash.fetch(ERRORS) { {} }
69
69
 
70
70
  @on_client_conflict = job_hash[ON_CLIENT_CONFLICT]
@@ -114,8 +114,8 @@ module SidekiqUniqueJobs
114
114
  #
115
115
  # @yield
116
116
  #
117
- def with_configured_loggers_context
118
- logger_method.call(logging_context) { yield }
117
+ def with_configured_loggers_context(&block)
118
+ logger_method.call(logging_context, &block)
119
119
  end
120
120
 
121
121
  #
@@ -18,15 +18,15 @@ module SidekiqUniqueJobs
18
18
  #
19
19
  # @yield when uniqueness is disable
20
20
  # @yield when the lock is successful
21
- def call(*)
22
- lock { yield }
21
+ def call(*, &block)
22
+ lock(&block)
23
23
  end
24
24
 
25
25
  private
26
26
 
27
27
  def lock
28
- if (token = lock_instance.lock)
29
- yield token
28
+ if (_token = lock_instance.lock)
29
+ yield
30
30
  else
31
31
  warn_about_duplicate
32
32
  end
@@ -19,8 +19,8 @@ module SidekiqUniqueJobs
19
19
  #
20
20
  # @yield when uniqueness is disabled
21
21
  # @yield when owning the lock
22
- def call(*)
23
- lock_instance.execute { yield }
22
+ def call(*, &block)
23
+ lock_instance.execute(&block)
24
24
  end
25
25
  end
26
26
  end
@@ -151,7 +151,7 @@ module SidekiqUniqueJobs
151
151
  conn.sscan_each("queues", &block)
152
152
  end
153
153
 
154
- def entries(conn, queue) # rubocop:disable Metrics/MethodLength
154
+ def entries(conn, queue, &block) # rubocop:disable Metrics/MethodLength
155
155
  queue_key = "queue:#{queue}"
156
156
  initial_size = conn.llen(queue_key)
157
157
  deleted_size = 0
@@ -166,9 +166,7 @@ module SidekiqUniqueJobs
166
166
 
167
167
  break if entries.empty?
168
168
 
169
- entries.each do |entry|
170
- yield entry
171
- end
169
+ entries.each(&block)
172
170
 
173
171
  deleted_size = initial_size - conn.llen(queue_key)
174
172
  end
@@ -35,7 +35,13 @@ module SidekiqUniqueJobs
35
35
  # The hook to call after a successful unlock
36
36
  # @return [Proc]
37
37
  def after_unlock_hook
38
- -> { worker_class.after_unlock if worker_method_defined?(:after_unlock) }
38
+ lambda do
39
+ if @worker_class.respond_to?(:after_unlock)
40
+ @worker_class.after_unlock # instance method in sidekiq v6
41
+ elsif worker_class.respond_to?(:after_unlock)
42
+ worker_class.after_unlock # class method regardless of sidekiq version
43
+ end
44
+ end
39
45
  end
40
46
 
41
47
  # Attempt to constantize a string worker_class argument, always
@@ -3,5 +3,5 @@
3
3
  module SidekiqUniqueJobs
4
4
  #
5
5
  # @return [String] the current SidekiqUniqueJobs version
6
- VERSION = "7.0.0.beta23"
6
+ VERSION = "7.0.0.beta24"
7
7
  end
@@ -7,10 +7,10 @@ module SidekiqUniqueJobs
7
7
  # @author Mikael Henriksson <mikael@zoolutions.se>
8
8
  #
9
9
  class VersionCheck
10
- PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength
10
+ PATTERN = /(?<operator1>[<>=]+)?\s?(?<version1>(\d+.?)+)(\s+&&\s+)?(?<operator2>[<>=]+)?\s?(?<version2>(\d+.?)+)?/m.freeze # rubocop:disable Layout/LineLength, Lint/MixedRegexpCaptureTypes
11
11
 
12
12
  #
13
- # Checks if a version is consrtaint is satisfied
13
+ # Checks if a version is constraint is satisfied
14
14
  #
15
15
  # @example A satisfied constraint
16
16
  # VersionCheck.satisfied?("5.0.0", ">= 4.0.0") #=> true
@@ -22,12 +22,31 @@ module SidekiqUniqueJobs
22
22
  # @param [String] version a version string `5.0.0`
23
23
  # @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
24
24
  #
25
- # @return [<type>] <description>
25
+ # @return [true, false] <description>
26
26
  #
27
27
  def self.satisfied?(version, constraint)
28
28
  new(version, constraint).satisfied?
29
29
  end
30
30
 
31
+ #
32
+ # Checks if a version is constraint is unfulfilled
33
+ #
34
+ # @example A satisfied constraint
35
+ # VersionCheck.unfulfilled?("5.0.0", ">= 4.0.0") #=> false
36
+ #
37
+ # @example An unfulfilled constraint
38
+ # VersionCheck.unfulfilled?("5.0.0", "<= 4.0.0") #=> true
39
+ #
40
+ #
41
+ # @param [String] version a version string `5.0.0`
42
+ # @param [String] constraint a version constraint `>= 5.0.0 <= 5.1.1`
43
+ #
44
+ # @return [true, false] <description>
45
+ #
46
+ def self.unfulfilled?(version, constraint)
47
+ !satisfied?(version, constraint)
48
+ end
49
+
31
50
  #
32
51
  # @!attribute [r] version
33
52
  # @return [String] a version string `5.0.0`
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.0.0.beta23
4
+ version: 7.0.0.beta24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-05 00:00:00.000000000 Z
11
+ date: 2020-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: brpoplpush-redis_script
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: 1.3.1
241
241
  requirements: []
242
- rubygems_version: 3.1.2
242
+ rubygems_version: 3.1.4
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: Sidekiq middleware that prevents duplicates jobs