sidekiq-unique-jobs 6.0.12 → 6.0.13

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: e400e981096ecad506646c8d3d8a57fdbe09628d344cd74bf3d4ebacaa717034
4
- data.tar.gz: 8eb32a66471a6fc9a8ab9bc5f8717dde2a544151bfb65dedb8214072f9fb14a7
3
+ metadata.gz: 75372204d0ab2439c631cf536b4e9ed87578e7117c4e2e183bff16e5d854172e
4
+ data.tar.gz: 0cbf2db1b5b271102509e290439a6590dea26c25c7aaa2c7e298a38bf8fe74e3
5
5
  SHA512:
6
- metadata.gz: 0036cec9334f5d1cf2ac814ed18efaff1adfe3cb372a8b593c686996ccade529faf18258c023313a64373a8d40389707cd5cc3515578f4b2a3062a7e2d9c51f5
7
- data.tar.gz: b0513ccbbdb7a72fdaea163c6a943df2b97bdcfcd4dad1637f28adfc8eb3f8107fa0a0ca0613ddd21fb0e91f5a82c1822913d9b7663df43f6b7ff739035b26a6
6
+ metadata.gz: c0cc1a9a25f7c7cfdab463fa4ce61b75ecec7e96744ddb84f4ebc68de39dd525b4d0359ab9891a96c34bff661cd87bd5853e5f7c7d40a3c983024f54bc6388ac
7
+ data.tar.gz: 3c0529e64d2bc3e40265339f16a8209b22c25bba4a6d264e341a45a0c057450b59dee0bc4b070f86df1e7174f5c6fec9c1df35cfb5bae3282b08e4aca9be2546
@@ -1,4 +1,5 @@
1
1
  require:
2
+ - rubocop-performance
2
3
  - rubocop-rspec
3
4
 
4
5
  inherit_mode:
@@ -64,6 +65,9 @@ Naming/FileName:
64
65
  Exclude:
65
66
  - lib/sidekiq-unique-jobs.rb
66
67
 
68
+ Naming/RescuedExceptionsVariableName:
69
+ PreferredName: ex
70
+
67
71
  Naming/UncommunicativeMethodParamName:
68
72
  AllowedNames:
69
73
  - ex
@@ -25,22 +25,21 @@ script:
25
25
 
26
26
  after_script:
27
27
  - if [[ "${COV}" = "true" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi;
28
-
29
28
  rvm:
30
- - 2.6.1
29
+ - 2.6.2
31
30
  - 2.4.5
32
31
  - 2.3.8
33
- - jruby-9.2.5.0
32
+ - jruby-9.2.7.0
34
33
 
35
34
  matrix:
36
35
  fast_finish: true
37
36
  include:
38
- - rvm: 2.5.3
37
+ - rvm: 2.5.5
39
38
  gemfile: gemfiles/sidekiq_develop.gemfile
40
39
  env: COV=true
41
- - rvm: 2.6.0
40
+ - rvm: 2.6.2
42
41
  gemfile: gemfiles/sidekiq_6.0.gemfile
43
- - rvm: 2.5.3
42
+ - rvm: 2.5.5
44
43
  gemfile: gemfiles/sidekiq_6.0.gemfile
45
44
 
46
45
  gemfile:
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## [v6.0.12](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v6.0.12) (2019-02-28)
4
+ [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v6.0.11...v6.0.12)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - we are receiving SidekiqUniqueJobs::ScriptError "Problem compiling convert\_legacy\_lock" after upgrading from 5.0.10 -\> 6.0.11 [\#377](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/377)
9
+ - Fix converting legacy locks [\#378](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/378) ([mhenrixon](https://github.com/mhenrixon))
10
+
3
11
  ## [v6.0.11](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v6.0.11) (2019-02-24)
4
12
  [Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v6.0.10...v6.0.11)
5
13
 
data/Gemfile CHANGED
@@ -19,8 +19,10 @@ platforms :mri_25 do
19
19
  gem "guard-rubocop"
20
20
  gem "memory_profiler"
21
21
  gem "pry"
22
+ gem "redcarpet", "~> 3.4"
22
23
  gem "reek", ">= 5.3"
23
24
  gem "rubocop"
25
+ gem "rubocop-performance"
24
26
  gem "rubocop-rspec"
25
27
  gem "simplecov-json"
26
28
  gem "travis"
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  - [Introduction](#introduction)
6
6
  - [Documentation](#documentation)
7
7
  - [Requirements](#requirements)
8
+ - [ActiveJob](#activejob)
9
+ - [redis-namespace](#redis-namespace)
8
10
  - [Installation](#installation)
9
11
  - [Support Me](#support-me)
10
12
  - [General Information](#general-information)
@@ -56,9 +58,17 @@ Below are links to the latest major versions (4 & 5):
56
58
 
57
59
  ## Requirements
58
60
 
59
- See [Sidekiq requirements][] for what is required. Starting from 5.0.0 only sidekiq >= 4 is supported and support for MRI <= 2.1 is dropped. ActiveJob is not supported
61
+ See [Sidekiq requirements][] for what is required. Starting from 5.0.0 only sidekiq >= 4 and MRI >= 2.2. ActiveJob is not supported
60
62
 
61
- Version 6 requires Redis >= 3 and pure Sidekiq, no ActiveJob supported anymore. See [About ActiveJob](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/About-ActiveJob) for why.
63
+ ### ActiveJob
64
+
65
+ Version 6 requires Redis >= 3 and pure Sidekiq, no ActiveJob supported anymore. See [About ActiveJob](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/About-ActiveJob) for why. It simply is too complex and generates more issues than I can handle given how little timer I have to spend on this project.
66
+
67
+ ### redis-namespace
68
+
69
+ Will not be officially supported anymore. Since Mike [won't support redis-namespace](https://github.com/mperham/sidekiq/issues/3366#issuecomment-284270120) neither will I.
70
+
71
+ [Read this](http://www.mikeperham.com/2017/04/10/migrating-from-redis-namespace/) for how to migrate away from namespacing.
62
72
 
63
73
  ## Installation
64
74
 
data/bin/bench CHANGED
@@ -10,11 +10,27 @@ require "benchmark/ips"
10
10
  require "sidekiq-unique-jobs"
11
11
 
12
12
  ITERATIONS ||= 10_000
13
+ LOCK_TYPES = %w[
14
+ until_executed
15
+ until_expired
16
+ until_and_while_executing
17
+ until_executing
18
+ while_executing
19
+ ].freeze
13
20
 
14
21
  Benchmark.ips do |x|
15
- x.config(time: 5, warmup: 2)
16
- x.report("new_shit") do |_times|
17
- SidekiqUniqueJobs::Scripts::AcquireLock.execute(nil, SecureRandom.hex, SecureRandom.hex)
22
+ x.config(time: 180, warmup: 2)
23
+ x.report("locksmith lock and unlock") do |_times|
24
+ item = {
25
+ "ttl" => rand(10),
26
+ "jid" => SecureRandom.hex,
27
+ "unique_digest" => SecureRandom.hex,
28
+ "lock" => LOCK_TYPES.sample,
29
+ }
30
+ locksmith = SidekiqUniqueJobs::Locksmith.new(item)
31
+ locksmith.lock
32
+ locksmith.unlock
18
33
  end
34
+
19
35
  x.compare!
20
36
  end
@@ -19,7 +19,6 @@ module SidekiqUniqueJobs
19
19
  return unless locked?
20
20
 
21
21
  unlock
22
-
23
22
  runtime_lock.execute { yield }
24
23
  end
25
24
 
@@ -16,6 +16,7 @@ module SidekiqUniqueJobs
16
16
  # @param [Hash] item the Sidekiq job hash
17
17
  # @param [Proc] callback callback to call after unlock
18
18
  # @param [Sidekiq::RedisConnection, ConnectionPool] redis_pool the redis connection
19
+ #
19
20
  def initialize(item, callback, redis_pool = nil)
20
21
  super(item, callback, redis_pool)
21
22
  append_unique_key_suffix
@@ -34,7 +35,12 @@ module SidekiqUniqueJobs
34
35
  def execute
35
36
  return strategy.call unless locksmith.lock(item[LOCK_TIMEOUT_KEY])
36
37
 
37
- with_cleanup { yield }
38
+ yield
39
+ rescue Exception # rubocop:disable Lint/RescueException
40
+ delete!
41
+ raise
42
+ else
43
+ unlock_with_callback
38
44
  end
39
45
 
40
46
  private
@@ -11,14 +11,6 @@ module SidekiqUniqueJobs
11
11
  #
12
12
  # @author Mikael Henriksson <mikael@zoolutions.se>
13
13
  class WhileExecutingReject < WhileExecuting
14
- # Executes in the Sidekiq server process
15
- # @yield to the worker class perform method
16
- def execute
17
- return strategy.call unless locksmith.lock(item[LOCK_TIMEOUT_KEY])
18
-
19
- with_cleanup { yield }
20
- end
21
-
22
14
  # Overridden with a forced {OnConflict::Reject} strategy
23
15
  # @return [OnConflict::Reject] a reject strategy
24
16
  def strategy
@@ -23,7 +23,10 @@ module SidekiqUniqueJobs
23
23
  @redis_pool = redis_pool
24
24
  end
25
25
 
26
+ #
26
27
  # Deletes the lock unless it has a ttl set
28
+ #
29
+ #
27
30
  def delete
28
31
  return if ttl
29
32
 
@@ -39,11 +42,14 @@ module SidekiqUniqueJobs
39
42
  )
40
43
  end
41
44
 
45
+ #
42
46
  # Create a lock for the item
47
+ #
43
48
  # @param [Integer] timeout the number of seconds to wait for a lock.
44
- # nil means wait indefinitely
45
- # @yield the block to execute if a lock is successful
46
- # @return the Sidekiq job_id (jid)
49
+ #
50
+ # @return [String] the Sidekiq job_id (jid)
51
+ #
52
+ #
47
53
  def lock(timeout = nil, &block)
48
54
  Scripts.call(:lock, redis_pool,
49
55
  keys: [exists_key, grabbed_key, available_key, UNIQUE_SET, unique_digest],
@@ -56,9 +62,12 @@ module SidekiqUniqueJobs
56
62
  end
57
63
  alias wait lock
58
64
 
65
+ #
59
66
  # Removes the lock keys from Redis if locked by the provided jid/token
67
+ #
60
68
  # @return [false] unless locked?
61
69
  # @return [String] Sidekiq job_id (jid) if successful
70
+ #
62
71
  def unlock(token = nil)
63
72
  token ||= jid
64
73
  return false unless locked?(token)
@@ -66,9 +75,14 @@ module SidekiqUniqueJobs
66
75
  unlock!(token)
67
76
  end
68
77
 
78
+ #
69
79
  # Removes the lock keys from Redis
80
+ #
81
+ # @param [String] token the token to unlock (defaults to jid)
82
+ #
70
83
  # @return [false] unless locked?
71
84
  # @return [String] Sidekiq job_id (jid) if successful
85
+ #
72
86
  def unlock!(token = nil)
73
87
  token ||= jid
74
88
 
@@ -80,10 +94,17 @@ module SidekiqUniqueJobs
80
94
  )
81
95
  end
82
96
 
83
- # Checks if this instance is considered locked
97
+ #
84
98
  # @param [String] token the unique token to check for a lock.
85
99
  # nil will default to the jid provided in the initializer
86
100
  # @return [true, false]
101
+ #
102
+ # Checks if this instance is considered locked
103
+ #
104
+ # @param [<type>] token <description>
105
+ #
106
+ # @return [<type>] <description>
107
+ #
87
108
  def locked?(token = nil)
88
109
  token ||= jid
89
110
 
@@ -16,14 +16,20 @@ module SidekiqUniqueJobs
16
16
 
17
17
  module_function
18
18
 
19
+ #
19
20
  # Call a lua script with the provided file_name
21
+ #
22
+ # @note this method is recursive if we need to load a lua script
23
+ # that wasn't previously loaded.
24
+ #
20
25
  # @param [Symbol] file_name the name of the lua script
21
26
  # @param [Sidekiq::RedisConnection, ConnectionPool] redis_pool the redis connection
22
27
  # @param [Hash] options arguments to pass to the script file
23
28
  # @option options [Array] :keys the array of keys to pass to the script
24
29
  # @option options [Array] :argv the array of arguments to pass to the script
25
- # @note this method is recursive if we need to load a lua script
26
- # that wasn't previously loaded.
30
+ #
31
+ # @return value from script
32
+ #
27
33
  def call(file_name, redis_pool, options = {})
28
34
  execute_script(file_name, redis_pool, options)
29
35
  rescue Redis::CommandError => ex
@@ -32,12 +38,17 @@ module SidekiqUniqueJobs
32
38
  end
33
39
  end
34
40
 
41
+ #
35
42
  # Execute the script file
43
+ #
36
44
  # @param [Symbol] file_name the name of the lua script
37
45
  # @param [Sidekiq::RedisConnection, ConnectionPool] redis_pool the redis connection
38
46
  # @param [Hash] options arguments to pass to the script file
39
47
  # @option options [Array] :keys the array of keys to pass to the script
40
48
  # @option options [Array] :argv the array of arguments to pass to the script
49
+ #
50
+ # @return value from script (evalsha)
51
+ #
41
52
  def execute_script(file_name, redis_pool, options = {})
42
53
  redis(redis_pool) do |conn|
43
54
  sha = script_sha(conn, file_name)
@@ -45,10 +56,15 @@ module SidekiqUniqueJobs
45
56
  end
46
57
  end
47
58
 
59
+ #
48
60
  # Return sha of already loaded lua script or load it and return the sha
61
+ #
49
62
  # @param [Sidekiq::RedisConnection] conn the redis connection
50
63
  # @param [Symbol] file_name the name of the lua script
51
64
  # @return [String] sha of the script file
65
+ #
66
+ # @return [String] the sha of the script
67
+ #
52
68
  def script_sha(conn, file_name)
53
69
  if (sha = SCRIPT_SHAS.get(file_name))
54
70
  return sha
@@ -59,10 +75,15 @@ module SidekiqUniqueJobs
59
75
  sha
60
76
  end
61
77
 
62
- # Return sha of already loaded lua script or load it and return the sha
78
+ #
79
+ # Handle errors to allow retrying errors that need retrying
80
+ #
63
81
  # @param [Redis::CommandError] ex exception to handle
64
82
  # @param [Symbol] file_name the name of the lua script
65
- # @raise [ScriptError] when the error isn't handled
83
+ #
84
+ # @return [void]
85
+ #
86
+ # @yieldreturn [void] yields back to the caller when NOSCRIPT is raised
66
87
  def handle_error(ex, file_name)
67
88
  if ex.message == "NOSCRIPT No matching script. Please use EVAL."
68
89
  SCRIPT_SHAS.delete(file_name)
@@ -72,16 +93,24 @@ module SidekiqUniqueJobs
72
93
  raise ScriptError, file_name: file_name, source_exception: ex
73
94
  end
74
95
 
96
+ #
75
97
  # Reads the lua file from disk
98
+ #
76
99
  # @param [Symbol] file_name the name of the lua script
100
+ #
77
101
  # @return [String] the content of the lua file
102
+ #
78
103
  def script_source(file_name)
79
104
  script_path(file_name).read
80
105
  end
81
106
 
107
+ #
82
108
  # Construct a Pathname to a lua script
109
+ #
83
110
  # @param [Symbol] file_name the name of the lua script
111
+ #
84
112
  # @return [Pathname] the full path to the gems lua script
113
+ #
85
114
  def script_path(file_name)
86
115
  LUA_PATHNAME.join("#{file_name}.lua")
87
116
  end
@@ -9,13 +9,19 @@ module SidekiqUniqueJobs
9
9
  include Logging
10
10
  include OptionsWithFallback
11
11
 
12
- # Runs the server middleware
13
- # Used from Sidekiq::Processor#process
12
+ #
13
+ #
14
+ # Runs the server middleware (used from Sidekiq::Processor#process)
15
+ #
14
16
  # @param [Sidekiq::Worker] worker_class
15
17
  # @param [Hash] item a sidekiq job hash
16
18
  # @param [String] queue name of the queue
19
+ #
20
+ # @see https://github.com/mperham/sidekiq/wiki/Job-Format
21
+ # @see https://github.com/mperham/sidekiq/wiki/Middleware
22
+ #
17
23
  # @yield when uniqueness is disabled
18
- # @yield when the lock class executes successfully
24
+ # @yield when the lock is acquired
19
25
  def call(worker_class, item, queue)
20
26
  @worker_class = worker_class
21
27
  @item = item
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqUniqueJobs
4
- VERSION = "6.0.12"
4
+ VERSION = "6.0.13"
5
5
  end
@@ -55,7 +55,7 @@ Gem::Specification.new do |spec|
55
55
  # ===== Documentation =====
56
56
  spec.add_development_dependency "github-markup", "~> 3.0"
57
57
  spec.add_development_dependency "github_changelog_generator", "~> 1.14"
58
- spec.add_development_dependency "redcarpet", "~> 3.4"
58
+ # spec.add_development_dependency "redcarpet", "~> 3.4"
59
59
  spec.add_development_dependency "yard", "~> 0.9.18"
60
60
 
61
61
  # ===== Release Management =====
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: 6.0.12
4
+ version: 6.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-28 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -176,20 +176,6 @@ dependencies:
176
176
  - - "~>"
177
177
  - !ruby/object:Gem::Version
178
178
  version: '1.14'
179
- - !ruby/object:Gem::Dependency
180
- name: redcarpet
181
- requirement: !ruby/object:Gem::Requirement
182
- requirements:
183
- - - "~>"
184
- - !ruby/object:Gem::Version
185
- version: '3.4'
186
- type: :development
187
- prerelease: false
188
- version_requirements: !ruby/object:Gem::Requirement
189
- requirements:
190
- - - "~>"
191
- - !ruby/object:Gem::Version
192
- version: '3.4'
193
179
  - !ruby/object:Gem::Dependency
194
180
  name: yard
195
181
  requirement: !ruby/object:Gem::Requirement
@@ -373,7 +359,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
373
359
  - !ruby/object:Gem::Version
374
360
  version: '0'
375
361
  requirements: []
376
- rubygems_version: 3.0.2
362
+ rubygems_version: 3.0.3
377
363
  signing_key:
378
364
  specification_version: 4
379
365
  summary: Sidekiq middleware that prevents duplicates jobs