sidekiq-unique-jobs 7.0.0.beta21 → 7.0.0.beta26

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.

Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -3
  3. data/README.md +48 -23
  4. data/lib/sidekiq_unique_jobs.rb +0 -1
  5. data/lib/sidekiq_unique_jobs/batch_delete.rb +1 -1
  6. data/lib/sidekiq_unique_jobs/changelog.rb +1 -1
  7. data/lib/sidekiq_unique_jobs/cli.rb +4 -2
  8. data/lib/sidekiq_unique_jobs/connection.rb +1 -1
  9. data/lib/sidekiq_unique_jobs/constants.rb +2 -1
  10. data/lib/sidekiq_unique_jobs/digests.rb +1 -1
  11. data/lib/sidekiq_unique_jobs/exceptions.rb +9 -9
  12. data/lib/sidekiq_unique_jobs/job.rb +5 -5
  13. data/lib/sidekiq_unique_jobs/json.rb +1 -1
  14. data/lib/sidekiq_unique_jobs/key.rb +1 -1
  15. data/lib/sidekiq_unique_jobs/lock.rb +1 -1
  16. data/lib/sidekiq_unique_jobs/lock/base_lock.rb +1 -1
  17. data/lib/sidekiq_unique_jobs/lock/client_validator.rb +1 -1
  18. data/lib/sidekiq_unique_jobs/lock/server_validator.rb +1 -1
  19. data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +1 -1
  20. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +1 -1
  21. data/lib/sidekiq_unique_jobs/lock/until_executing.rb +1 -1
  22. data/lib/sidekiq_unique_jobs/lock/until_expired.rb +1 -1
  23. data/lib/sidekiq_unique_jobs/lock/validator.rb +1 -1
  24. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +1 -1
  25. data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +1 -1
  26. data/lib/sidekiq_unique_jobs/lock_args.rb +2 -2
  27. data/lib/sidekiq_unique_jobs/lock_config.rb +5 -5
  28. data/lib/sidekiq_unique_jobs/lock_digest.rb +2 -2
  29. data/lib/sidekiq_unique_jobs/lock_info.rb +1 -1
  30. data/lib/sidekiq_unique_jobs/lock_timeout.rb +1 -1
  31. data/lib/sidekiq_unique_jobs/lock_ttl.rb +1 -1
  32. data/lib/sidekiq_unique_jobs/locksmith.rb +1 -1
  33. data/lib/sidekiq_unique_jobs/logging.rb +3 -3
  34. data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +2 -2
  35. data/lib/sidekiq_unique_jobs/lua/reap_orphans.lua +1 -5
  36. data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_queue.lua +3 -0
  37. data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua +16 -5
  38. data/lib/sidekiq_unique_jobs/middleware.rb +16 -4
  39. data/lib/sidekiq_unique_jobs/middleware/client.rb +5 -5
  40. data/lib/sidekiq_unique_jobs/middleware/server.rb +3 -3
  41. data/lib/sidekiq_unique_jobs/normalizer.rb +1 -1
  42. data/lib/sidekiq_unique_jobs/on_conflict.rb +1 -1
  43. data/lib/sidekiq_unique_jobs/on_conflict/log.rb +1 -1
  44. data/lib/sidekiq_unique_jobs/on_conflict/null_strategy.rb +1 -1
  45. data/lib/sidekiq_unique_jobs/on_conflict/raise.rb +1 -1
  46. data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +2 -2
  47. data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +1 -1
  48. data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +1 -1
  49. data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +1 -1
  50. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +1 -1
  51. data/lib/sidekiq_unique_jobs/orphans/lua_reaper.rb +1 -1
  52. data/lib/sidekiq_unique_jobs/orphans/manager.rb +35 -4
  53. data/lib/sidekiq_unique_jobs/orphans/null_reaper.rb +24 -0
  54. data/lib/sidekiq_unique_jobs/orphans/observer.rb +2 -2
  55. data/lib/sidekiq_unique_jobs/orphans/reaper.rb +5 -1
  56. data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +18 -11
  57. data/lib/sidekiq_unique_jobs/profiler.rb +1 -1
  58. data/lib/sidekiq_unique_jobs/redis.rb +1 -1
  59. data/lib/sidekiq_unique_jobs/redis/entity.rb +1 -1
  60. data/lib/sidekiq_unique_jobs/redis/hash.rb +1 -1
  61. data/lib/sidekiq_unique_jobs/redis/list.rb +1 -1
  62. data/lib/sidekiq_unique_jobs/redis/set.rb +1 -1
  63. data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +1 -1
  64. data/lib/sidekiq_unique_jobs/redis/string.rb +1 -1
  65. data/lib/sidekiq_unique_jobs/rspec/matchers.rb +2 -2
  66. data/lib/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options.rb +2 -2
  67. data/lib/sidekiq_unique_jobs/script.rb +1 -1
  68. data/lib/sidekiq_unique_jobs/script/caller.rb +2 -2
  69. data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +5 -5
  70. data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +1 -1
  71. data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +8 -2
  72. data/lib/sidekiq_unique_jobs/timing.rb +1 -1
  73. data/lib/sidekiq_unique_jobs/unlockable.rb +1 -1
  74. data/lib/sidekiq_unique_jobs/update_version.rb +1 -1
  75. data/lib/sidekiq_unique_jobs/upgrade_locks.rb +1 -1
  76. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  77. data/lib/sidekiq_unique_jobs/version_check.rb +23 -4
  78. data/lib/sidekiq_unique_jobs/web.rb +1 -1
  79. data/lib/sidekiq_unique_jobs/web/helpers.rb +1 -1
  80. metadata +6 -5
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Utility class to append uniqueness to the sidekiq job hash
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  module Job
8
8
  extend self
9
9
 
@@ -40,19 +40,19 @@ module SidekiqUniqueJobs
40
40
  end
41
41
 
42
42
  def add_lock_timeout(item)
43
- item[LOCK_TIMEOUT] = SidekiqUniqueJobs::LockTimeout.calculate(item)
43
+ item[LOCK_TIMEOUT] ||= SidekiqUniqueJobs::LockTimeout.calculate(item)
44
44
  end
45
45
 
46
46
  def add_lock_args(item)
47
- item[LOCK_ARGS] = SidekiqUniqueJobs::LockArgs.call(item)
47
+ item[LOCK_ARGS] ||= SidekiqUniqueJobs::LockArgs.call(item)
48
48
  end
49
49
 
50
50
  def add_lock_digest(item)
51
- item[LOCK_DIGEST] = SidekiqUniqueJobs::LockDigest.call(item)
51
+ item[LOCK_DIGEST] ||= SidekiqUniqueJobs::LockDigest.call(item)
52
52
  end
53
53
 
54
54
  def add_lock_prefix(item)
55
- item[LOCK_PREFIX] = SidekiqUniqueJobs.config.unique_prefix
55
+ item[LOCK_PREFIX] ||= SidekiqUniqueJobs.config.unique_prefix
56
56
  end
57
57
  end
58
58
  end
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Handles loading and dumping of json
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  module JSON
8
8
  module_function
9
9
 
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Key class wraps logic dealing with various lock keys
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  class Key
8
8
  #
9
9
  # @!attribute [r] digest
@@ -4,7 +4,7 @@ module SidekiqUniqueJobs
4
4
  #
5
5
  # Class Lock provides access to information about a lock
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  #
9
9
  class Lock # rubocop:disable Metrics/ClassLength
10
10
  # includes "SidekiqUniqueJobs::Connection"
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  # Abstract base class for locks
6
6
  #
7
7
  # @abstract
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  class BaseLock
10
10
  include SidekiqUniqueJobs::Logging
11
11
 
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  #
6
6
  # Validates the sidekiq options for the Sidekiq client process
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  #
10
10
  class ClientValidator
11
11
  #
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  #
6
6
  # Validates the sidekiq options for the Sidekiq server process
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  #
10
10
  class ServerValidator
11
11
  #
@@ -11,7 +11,7 @@ module SidekiqUniqueJobs
11
11
  # See {#lock} for more information about the client.
12
12
  # See {#execute} for more information about the server
13
13
  #
14
- # @author Mikael Henriksson <mikael@zoolutions.se>
14
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
15
15
  class UntilAndWhileExecuting < BaseLock
16
16
  # Executes in the Sidekiq server process
17
17
  # @yield to the worker class perform method
@@ -6,7 +6,7 @@ module SidekiqUniqueJobs
6
6
  # - Locks on perform_in or perform_async
7
7
  # - Unlocks after yielding to the worker's perform method
8
8
  #
9
- # @author Mikael Henriksson <mikael@zoolutions.se>
9
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
10
10
  class UntilExecuted < BaseLock
11
11
  OK ||= "OK"
12
12
 
@@ -6,7 +6,7 @@ module SidekiqUniqueJobs
6
6
  # - Locks on perform_in or perform_async
7
7
  # - Unlocks before yielding to the worker's perform method
8
8
  #
9
- # @author Mikael Henriksson <mikael@zoolutions.se>
9
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
10
10
  class UntilExecuting < BaseLock
11
11
  # Executes in the Sidekiq server process
12
12
  # @yield to the worker class perform method
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  #
6
6
  # UntilExpired locks until the job expires
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  #
10
10
  class UntilExpired < UntilExecuted
11
11
  end
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  #
6
6
  # Validator base class to avoid some duplication
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  #
10
10
  class Validator
11
11
  #
@@ -9,7 +9,7 @@ module SidekiqUniqueJobs
9
9
  # See {#lock} for more information about the client.
10
10
  # See {#execute} for more information about the server
11
11
  #
12
- # @author Mikael Henriksson <mikael@zoolutions.se>
12
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
13
13
  class WhileExecuting < BaseLock
14
14
  RUN_SUFFIX ||= ":RUN"
15
15
 
@@ -9,7 +9,7 @@ module SidekiqUniqueJobs
9
9
  # See {#lock} for more information about the client.
10
10
  # See {#execute} for more information about the server
11
11
  #
12
- # @author Mikael Henriksson <mikael@zoolutions.se>
12
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
13
13
  class WhileExecutingReject < WhileExecuting
14
14
  # Overridden with a forced {OnConflict::Reject} strategy
15
15
  # @return [OnConflict::Reject] a reject strategy
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Handles uniqueness of sidekiq arguments
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  class LockArgs
8
8
  include SidekiqUniqueJobs::Logging
9
9
  include SidekiqUniqueJobs::SidekiqWorkerMethods
@@ -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)
@@ -5,7 +5,7 @@ module SidekiqUniqueJobs
5
5
  # Gathers all configuration for a lock
6
6
  # which helps reduce the amount of instance variables
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  #
10
10
  class LockConfig
11
11
  #
@@ -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]
@@ -5,7 +5,7 @@ require "openssl"
5
5
  module SidekiqUniqueJobs
6
6
  # Handles uniqueness of sidekiq arguments
7
7
  #
8
- # @author Mikael Henriksson <mikael@zoolutions.se>
8
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
9
9
  class LockDigest
10
10
  include SidekiqUniqueJobs::Logging
11
11
  include SidekiqUniqueJobs::JSON
@@ -58,7 +58,7 @@ module SidekiqUniqueJobs
58
58
  # Filter a hash to use for digest
59
59
  # @return [Hash] to use for digest
60
60
  def digestable_hash
61
- @item.slice(CLASS, QUEUE, LOCK_ARGS).tap do |hash|
61
+ @item.slice(CLASS, QUEUE, LOCK_ARGS, APARTMENT).tap do |hash|
62
62
  hash.delete(QUEUE) if unique_across_queues?
63
63
  hash.delete(CLASS) if unique_across_workers?
64
64
  end
@@ -4,7 +4,7 @@ module SidekiqUniqueJobs
4
4
  #
5
5
  # Class Info provides information about a lock
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  #
9
9
  class LockInfo < Redis::String
10
10
  #
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Calculates timeout and expiration
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  class LockTimeout
8
8
  # includes "SidekiqUniqueJobs::SidekiqWorkerMethods"
9
9
  # @!parse include SidekiqUniqueJobs::SidekiqWorkerMethods
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Calculates timeout and expiration
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  class LockTTL
8
8
  # includes "SidekiqUniqueJobs::SidekiqWorkerMethods"
9
9
  # @!parse include SidekiqUniqueJobs::SidekiqWorkerMethods
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Lock manager class that handles all the various locks
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  class Locksmith # rubocop:disable Metrics/ClassLength
8
8
  # includes "SidekiqUniqueJobs::Connection"
9
9
  # @!parse include SidekiqUniqueJobs::Connection
@@ -3,7 +3,7 @@
3
3
  module SidekiqUniqueJobs
4
4
  # Utility module for reducing the number of uses of logger.
5
5
  #
6
- # @author Mikael Henriksson <mikael@zoolutions.se>
6
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  module Logging
8
8
  def self.included(base)
9
9
  base.send(:extend, self)
@@ -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
  #
@@ -4,13 +4,13 @@ module SidekiqUniqueJobs
4
4
  #
5
5
  # Provides the sidekiq middleware that makes the gem work
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  #
9
9
  module Logging
10
10
  #
11
11
  # Context aware logging for Sidekiq Middlewares
12
12
  #
13
- # @author Mikael Henriksson <mikael@zoolutions.se>
13
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
14
14
  #
15
15
  module Middleware
16
16
  include Logging
@@ -65,11 +65,7 @@ repeat
65
65
  -- TODO: Add check for jobs checked out by process
66
66
  if found ~= true then
67
67
  log_debug("Searching for digest:", digest, "in process sets")
68
- local queue = find_digest_in_process_set(digest)
69
- if queue then
70
- log_debug("found digest:", digest, "in queue:", queue)
71
- found = true
72
- end
68
+ found = find_digest_in_process_set(digest)
73
69
  end
74
70
 
75
71
  if found ~= true then
@@ -6,6 +6,9 @@ local function delete_from_queue(queue, digest)
6
6
 
7
7
  while (index < total) do
8
8
  local items = redis.call("LRANGE", queue, index, index + per -1)
9
+ if #items == 0 then
10
+ break
11
+ end
9
12
  for _, item in pairs(items) do
10
13
  if string.find(item, digest) then
11
14
  redis.call("LREM", queue, 1, item)
@@ -4,7 +4,7 @@ local function find_digest_in_process_set(digest)
4
4
  local pattern = "*" .. digest .. "*"
5
5
  local found = false
6
6
 
7
- log_debug("searching in list processes:",
7
+ log_debug("Searching in process list",
8
8
  "for digest:", digest,
9
9
  "cursor:", process_cursor)
10
10
 
@@ -15,15 +15,26 @@ local function find_digest_in_process_set(digest)
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
19
  log_debug("searching in process set:", process,
19
20
  "for digest:", digest,
20
21
  "cursor:", process_cursor)
21
22
 
22
- local job = redis.call("HGET", process, "info")
23
+ local jobs = redis.call("HGETALL", workers_key)
23
24
 
24
- if string.find(job, digest) then
25
- log_debug("Found digest", digest, "in process:", process)
26
- found = true
25
+ if #jobs == 0 then
26
+ log_debug("No entries in:", workers_key)
27
+ else
28
+ for i = 1, #jobs, 2 do
29
+ if string.find(jobs[i +1], digest) then
30
+ log_debug("Found digest", digest, "in:", workers_key)
31
+ found = true
32
+ break
33
+ end
34
+ end
35
+ end
36
+
37
+ if found == true then
27
38
  break
28
39
  end
29
40
  end
@@ -4,7 +4,7 @@ module SidekiqUniqueJobs
4
4
  #
5
5
  # Provides the sidekiq middleware that makes the gem work
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  #
9
9
  module Middleware
10
10
  include SidekiqUniqueJobs::Logging::Middleware
@@ -25,11 +25,19 @@ module SidekiqUniqueJobs
25
25
  def self.configure_server # rubocop:disable Metrics/MethodLength
26
26
  Sidekiq.configure_server do |config|
27
27
  config.client_middleware do |chain|
28
- chain.add SidekiqUniqueJobs::Middleware::Client
28
+ if defined?(Apartment::Sidekiq::Middleware::Client)
29
+ chain.insert_after Apartment::Sidekiq::Middleware::Client, SidekiqUniqueJobs::Middleware::Client
30
+ else
31
+ chain.add SidekiqUniqueJobs::Middleware::Client
32
+ end
29
33
  end
30
34
 
31
35
  config.server_middleware do |chain|
32
- chain.add SidekiqUniqueJobs::Middleware::Server
36
+ if defined?(Apartment::Sidekiq::Middleware::Server)
37
+ chain.insert_after Apartment::Sidekiq::Middleware::Server, SidekiqUniqueJobs::Middleware::Server
38
+ else
39
+ chain.add SidekiqUniqueJobs::Middleware::Server
40
+ end
33
41
  end
34
42
 
35
43
  config.on(:startup) do
@@ -51,7 +59,11 @@ module SidekiqUniqueJobs
51
59
  def self.configure_client
52
60
  Sidekiq.configure_client do |config|
53
61
  config.client_middleware do |chain|
54
- chain.add SidekiqUniqueJobs::Middleware::Client
62
+ if defined?(Apartment::Sidekiq::Middleware::Client)
63
+ chain.insert_after Apartment::Sidekiq::Middleware::Client, SidekiqUniqueJobs::Middleware::Client
64
+ else
65
+ chain.add SidekiqUniqueJobs::Middleware::Client
66
+ end
55
67
  end
56
68
  end
57
69
  end
@@ -4,7 +4,7 @@ module SidekiqUniqueJobs
4
4
  module Middleware
5
5
  # The unique sidekiq middleware for the client push
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  class Client
9
9
  prepend SidekiqUniqueJobs::Middleware
10
10
 
@@ -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
@@ -4,7 +4,7 @@ module SidekiqUniqueJobs
4
4
  module Middleware
5
5
  # The unique sidekiq middleware for the server processor
6
6
  #
7
- # @author Mikael Henriksson <mikael@zoolutions.se>
7
+ # @author Mikael Henriksson <mikael@mhenrixon.com>
8
8
  class Server
9
9
  prepend SidekiqUniqueJobs::Middleware
10
10
 
@@ -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