sidekiq-unique-jobs 6.0.25 → 7.0.0.beta2

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +155 -20
  3. data/README.md +349 -112
  4. data/lib/sidekiq-unique-jobs.rb +2 -0
  5. data/lib/sidekiq_unique_jobs.rb +43 -6
  6. data/lib/sidekiq_unique_jobs/batch_delete.rb +121 -0
  7. data/lib/sidekiq_unique_jobs/changelog.rb +71 -0
  8. data/lib/sidekiq_unique_jobs/cli.rb +20 -29
  9. data/lib/sidekiq_unique_jobs/config.rb +193 -0
  10. data/lib/sidekiq_unique_jobs/connection.rb +5 -4
  11. data/lib/sidekiq_unique_jobs/constants.rb +36 -24
  12. data/lib/sidekiq_unique_jobs/core_ext.rb +38 -0
  13. data/lib/sidekiq_unique_jobs/digests.rb +78 -93
  14. data/lib/sidekiq_unique_jobs/exceptions.rb +152 -8
  15. data/lib/sidekiq_unique_jobs/job.rb +3 -3
  16. data/lib/sidekiq_unique_jobs/json.rb +34 -0
  17. data/lib/sidekiq_unique_jobs/key.rb +93 -0
  18. data/lib/sidekiq_unique_jobs/lock.rb +295 -0
  19. data/lib/sidekiq_unique_jobs/lock/base_lock.rb +49 -43
  20. data/lib/sidekiq_unique_jobs/lock/client_validator.rb +28 -0
  21. data/lib/sidekiq_unique_jobs/lock/server_validator.rb +27 -0
  22. data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +8 -17
  23. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +5 -5
  24. data/lib/sidekiq_unique_jobs/lock/until_expired.rb +1 -23
  25. data/lib/sidekiq_unique_jobs/lock/validator.rb +65 -0
  26. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +12 -8
  27. data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +1 -1
  28. data/lib/sidekiq_unique_jobs/lock_config.rb +95 -0
  29. data/lib/sidekiq_unique_jobs/lock_info.rb +68 -0
  30. data/lib/sidekiq_unique_jobs/locksmith.rb +255 -99
  31. data/lib/sidekiq_unique_jobs/logging.rb +148 -22
  32. data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +44 -0
  33. data/lib/sidekiq_unique_jobs/lua/delete.lua +51 -0
  34. data/lib/sidekiq_unique_jobs/lua/delete_by_digest.lua +46 -0
  35. data/lib/sidekiq_unique_jobs/lua/delete_job_by_digest.lua +38 -0
  36. data/lib/sidekiq_unique_jobs/lua/find_digest_in_queues.lua +26 -0
  37. data/lib/sidekiq_unique_jobs/lua/find_digest_in_sorted_set.lua +24 -0
  38. data/lib/sidekiq_unique_jobs/lua/lock.lua +91 -0
  39. data/lib/sidekiq_unique_jobs/lua/locked.lua +35 -0
  40. data/lib/sidekiq_unique_jobs/lua/queue.lua +83 -0
  41. data/lib/sidekiq_unique_jobs/lua/reap_orphans.lua +86 -0
  42. data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +40 -0
  43. data/lib/sidekiq_unique_jobs/lua/shared/_current_time.lua +8 -0
  44. data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_queue.lua +19 -0
  45. data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua +18 -0
  46. data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_queues.lua +46 -0
  47. data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_sorted_set.lua +24 -0
  48. data/lib/sidekiq_unique_jobs/lua/shared/_hgetall.lua +13 -0
  49. data/lib/sidekiq_unique_jobs/lua/shared/_upgrades.lua +3 -0
  50. data/lib/sidekiq_unique_jobs/lua/shared/find_digest_in_sorted_set.lua +24 -0
  51. data/lib/sidekiq_unique_jobs/lua/unlock.lua +99 -0
  52. data/lib/sidekiq_unique_jobs/lua/update_version.lua +40 -0
  53. data/lib/sidekiq_unique_jobs/lua/upgrade.lua +68 -0
  54. data/lib/sidekiq_unique_jobs/middleware.rb +62 -31
  55. data/lib/sidekiq_unique_jobs/middleware/client.rb +42 -0
  56. data/lib/sidekiq_unique_jobs/middleware/server.rb +27 -0
  57. data/lib/sidekiq_unique_jobs/normalizer.rb +3 -3
  58. data/lib/sidekiq_unique_jobs/on_conflict.rb +22 -9
  59. data/lib/sidekiq_unique_jobs/on_conflict/log.rb +8 -4
  60. data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +59 -13
  61. data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +42 -13
  62. data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +4 -4
  63. data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +24 -5
  64. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +47 -23
  65. data/lib/sidekiq_unique_jobs/orphans/manager.rb +100 -0
  66. data/lib/sidekiq_unique_jobs/orphans/observer.rb +42 -0
  67. data/lib/sidekiq_unique_jobs/orphans/reaper.rb +201 -0
  68. data/lib/sidekiq_unique_jobs/profiler.rb +51 -0
  69. data/lib/sidekiq_unique_jobs/redis.rb +11 -0
  70. data/lib/sidekiq_unique_jobs/redis/entity.rb +94 -0
  71. data/lib/sidekiq_unique_jobs/redis/hash.rb +56 -0
  72. data/lib/sidekiq_unique_jobs/redis/list.rb +32 -0
  73. data/lib/sidekiq_unique_jobs/redis/set.rb +32 -0
  74. data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +59 -0
  75. data/lib/sidekiq_unique_jobs/redis/string.rb +49 -0
  76. data/lib/sidekiq_unique_jobs/rspec/matchers.rb +19 -0
  77. data/lib/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options.rb +43 -0
  78. data/lib/sidekiq_unique_jobs/{scripts.rb → script.rb} +43 -29
  79. data/lib/sidekiq_unique_jobs/script/caller.rb +125 -0
  80. data/lib/sidekiq_unique_jobs/script/template.rb +41 -0
  81. data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +92 -65
  82. data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +166 -28
  83. data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +10 -11
  84. data/lib/sidekiq_unique_jobs/testing.rb +47 -15
  85. data/lib/sidekiq_unique_jobs/time_calculator.rb +103 -0
  86. data/lib/sidekiq_unique_jobs/timing.rb +58 -0
  87. data/lib/sidekiq_unique_jobs/unique_args.rb +19 -21
  88. data/lib/sidekiq_unique_jobs/unlockable.rb +11 -2
  89. data/lib/sidekiq_unique_jobs/update_version.rb +25 -0
  90. data/lib/sidekiq_unique_jobs/upgrade_locks.rb +151 -0
  91. data/lib/sidekiq_unique_jobs/version.rb +3 -1
  92. data/lib/sidekiq_unique_jobs/version_check.rb +1 -1
  93. data/lib/sidekiq_unique_jobs/web.rb +25 -19
  94. data/lib/sidekiq_unique_jobs/web/helpers.rb +98 -6
  95. data/lib/sidekiq_unique_jobs/web/views/lock.erb +108 -0
  96. data/lib/sidekiq_unique_jobs/web/views/locks.erb +52 -0
  97. data/lib/tasks/changelog.rake +4 -3
  98. metadata +70 -35
  99. data/lib/sidekiq_unique_jobs/client/middleware.rb +0 -56
  100. data/lib/sidekiq_unique_jobs/server/middleware.rb +0 -46
  101. data/lib/sidekiq_unique_jobs/timeout.rb +0 -8
  102. data/lib/sidekiq_unique_jobs/timeout/calculator.rb +0 -63
  103. data/lib/sidekiq_unique_jobs/util.rb +0 -103
  104. data/lib/sidekiq_unique_jobs/web/views/unique_digest.erb +0 -28
  105. data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +0 -46
  106. data/redis/acquire_lock.lua +0 -21
  107. data/redis/convert_legacy_lock.lua +0 -13
  108. data/redis/delete.lua +0 -14
  109. data/redis/delete_by_digest.lua +0 -23
  110. data/redis/delete_job_by_digest.lua +0 -60
  111. data/redis/lock.lua +0 -62
  112. data/redis/release_stale_locks.lua +0 -90
  113. data/redis/unlock.lua +0 -35
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json"
4
-
5
3
  module SidekiqUniqueJobs
6
4
  # Normalizes hashes by dumping them to json and loading them from json
7
5
  #
8
6
  # @author Mikael Henriksson <mikael@zoolutions.se>
9
7
  module Normalizer
8
+ extend SidekiqUniqueJobs::JSON
9
+
10
10
  # Changes hash to a json compatible hash
11
11
  # @param [Hash] args
12
12
  # @return [Hash] a json compatible hash
13
13
  def self.jsonify(args)
14
- Sidekiq.load_json(Sidekiq.dump_json(args))
14
+ load_json(dump_json(args))
15
15
  end
16
16
  end
17
17
  end
@@ -15,17 +15,30 @@ module SidekiqUniqueJobs
15
15
  # @author Mikael Henriksson <mikael@zoolutions.se>
16
16
  #
17
17
  module OnConflict
18
- STRATEGIES = {
19
- log: OnConflict::Log,
20
- raise: OnConflict::Raise,
21
- reject: OnConflict::Reject,
22
- replace: OnConflict::Replace,
23
- reschedule: OnConflict::Reschedule,
24
- }.freeze
18
+ # A convenience method for using the configured strategies
19
+ def self.strategies
20
+ SidekiqUniqueJobs.strategies
21
+ end
25
22
 
26
- # returns OnConflict::NullStrategy when no other could be found
23
+ #
24
+ # Find a strategy to use for conflicting locks
25
+ #
26
+ # @param [Symbol] strategy the key for the strategy
27
+ #
28
+ # @return [OnConflict::Strategy] when found
29
+ # @return [OnConflict::NullStrategy] when no other could be found
30
+ #
27
31
  def self.find_strategy(strategy)
28
- STRATEGIES.fetch(strategy.to_s.to_sym) { OnConflict::NullStrategy }
32
+ return OnConflict::NullStrategy unless strategy
33
+
34
+ strategies.fetch(strategy.to_sym) do
35
+ SidekiqUniqueJobs.logger.warn(
36
+ "No matching implementation for strategy: #{strategy}, returning OnConflict::NullStrategy." \
37
+ " Available strategies are (#{strategies.inspect})",
38
+ )
39
+
40
+ OnConflict::NullStrategy
41
+ end
29
42
  end
30
43
  end
31
44
  end
@@ -8,12 +8,16 @@ module SidekiqUniqueJobs
8
8
  class Log < OnConflict::Strategy
9
9
  include SidekiqUniqueJobs::Logging
10
10
 
11
+ #
11
12
  # Logs an informational message about that the job was not unique
13
+ #
14
+ #
15
+ # @return [void]
16
+ #
12
17
  def call
13
- log_info(
14
- "skipping job with id (#{item[JID_KEY]}) " \
15
- "because unique_digest: (#{item[UNIQUE_DIGEST_KEY]}) already exists",
16
- )
18
+ log_info(<<~MESSAGE.chomp)
19
+ Skipping job with id (#{item[JID]}) because unique_digest: (#{item[UNIQUE_DIGEST]}) already exists
20
+ MESSAGE
17
21
  end
18
22
  end
19
23
  end
@@ -6,14 +6,11 @@ module SidekiqUniqueJobs
6
6
  #
7
7
  # @author Mikael Henriksson <mikael@zoolutions.se>
8
8
  class Reject < OnConflict::Strategy
9
+ include SidekiqUniqueJobs::Timing
10
+
9
11
  # Send jobs to dead queue
10
12
  def call
11
- log_debug { "Rejecting job with jid: #{item[JID_KEY]}" }
12
- send_to_deadset
13
- end
14
-
15
- def send_to_deadset
16
- log_info { "Adding dead #{item[CLASS_KEY]} job #{item[JID_KEY]}" }
13
+ log_info { "Adding dead #{item[CLASS]} job #{item[JID]}" }
17
14
 
18
15
  if deadset_kill?
19
16
  deadset_kill
@@ -22,10 +19,25 @@ module SidekiqUniqueJobs
22
19
  end
23
20
  end
24
21
 
22
+ #
23
+ # Sidekiq version compatibility check
24
+ # @api private
25
+ #
26
+ #
27
+ # @return [true, false] depending on if Sidekiq::Deadset responds to kill
28
+ #
25
29
  def deadset_kill?
26
30
  deadset.respond_to?(:kill)
27
31
  end
28
32
 
33
+ #
34
+ # Use Sidekiqs built in Sidekiq::DeadSet#kill
35
+ # to get rid of the job
36
+ # @api private
37
+ #
38
+ #
39
+ # @return [void]
40
+ #
29
41
  def deadset_kill
30
42
  if kill_with_options?
31
43
  kill_job_with_options
@@ -34,36 +46,70 @@ module SidekiqUniqueJobs
34
46
  end
35
47
  end
36
48
 
49
+ #
50
+ # Sidekiq version compatibility check
51
+ # @api private
52
+ #
53
+ #
54
+ # @return [true] when Sidekiq::Deadset#kill takes more than 1 argument
55
+ # @return [false] when Sidekiq::Deadset#kill does not take multiple arguments
56
+ #
37
57
  def kill_with_options?
38
58
  Sidekiq::DeadSet.instance_method(:kill).arity > 1
39
59
  end
40
60
 
61
+ #
62
+ # Executes the kill instructions without arguments
63
+ # @api private
64
+ #
65
+ # @return [void]
66
+ #
41
67
  def kill_job_without_options
42
68
  deadset.kill(payload)
43
69
  end
44
70
 
71
+ #
72
+ # Executes the kill instructions with arguments
73
+ # @api private
74
+ #
75
+ # @return [void]
76
+ #
45
77
  def kill_job_with_options
46
78
  deadset.kill(payload, notify_failure: false)
47
79
  end
48
80
 
81
+ #
82
+ # An instance of Sidekiq::Deadset
83
+ # @api private
84
+ #
85
+ # @return [Sidekiq::Deadset]>
86
+ #
49
87
  def deadset
50
88
  @deadset ||= Sidekiq::DeadSet.new
51
89
  end
52
90
 
91
+ #
92
+ # Used for compatibility with older Sidekiq versions
93
+ #
94
+ #
95
+ # @return [void]
96
+ #
53
97
  def push_to_deadset
54
- Sidekiq.redis do |conn|
98
+ redis do |conn|
55
99
  conn.multi do
56
- conn.zadd("dead", current_time, payload)
57
- conn.zremrangebyscore("dead", "-inf", current_time - Sidekiq::DeadSet.timeout)
100
+ conn.zadd("dead", now_f, payload)
101
+ conn.zremrangebyscore("dead", "-inf", now_f - Sidekiq::DeadSet.timeout)
58
102
  conn.zremrangebyrank("dead", 0, -Sidekiq::DeadSet.max_jobs)
59
103
  end
60
104
  end
61
105
  end
62
106
 
63
- def current_time
64
- @current_time ||= Time.now.to_f
65
- end
66
-
107
+ #
108
+ # The Sidekiq job hash as JSON
109
+ #
110
+ #
111
+ # @return [String] a JSON formatted string
112
+ #
67
113
  def payload
68
114
  @payload ||= Sidekiq.dump_json(item)
69
115
  end
@@ -6,36 +6,65 @@ module SidekiqUniqueJobs
6
6
  #
7
7
  # @author Mikael Henriksson <mikael@zoolutions.se>
8
8
  class Replace < OnConflict::Strategy
9
- attr_reader :queue, :unique_digest
9
+ #
10
+ # @!attribute [r] queue
11
+ # @return [String] rthe sidekiq queue this job belongs to
12
+ attr_reader :queue
13
+ #
14
+ # @!attribute [r] unique_digest
15
+ # @return [String] the unique digest to use for locking
16
+ attr_reader :unique_digest
10
17
 
18
+ #
19
+ # Initialize a new Replace strategy
20
+ #
11
21
  # @param [Hash] item sidekiq job hash
12
- def initialize(item)
13
- super
14
- @queue = item[QUEUE_KEY]
15
- @unique_digest = item[UNIQUE_DIGEST_KEY]
22
+ #
23
+ def initialize(item, redis_pool = nil)
24
+ super(item, redis_pool)
25
+ @queue = item[QUEUE]
26
+ @unique_digest = item[UNIQUE_DIGEST]
16
27
  end
17
28
 
29
+ #
18
30
  # Replace the old job in the queue
31
+ #
32
+ #
33
+ # @return [void] <description>
34
+ #
19
35
  # @yield to retry the lock after deleting the old one
36
+ #
20
37
  def call(&block)
21
- return unless delete_job_by_digest
38
+ return unless (deleted_job = delete_job_by_digest)
22
39
 
23
- delete_lock
40
+ log_info("Deleting job: #{deleted_job}")
41
+ if (del_count = delete_lock)
42
+ log_info("Deleted `#{del_count}` keys for #{unique_digest}")
43
+ end
24
44
  block&.call
25
45
  end
26
46
 
47
+ #
27
48
  # Delete the job from either schedule, retry or the queue
49
+ #
50
+ #
51
+ # @return [String] the deleted job hash
52
+ # @return [nil] when deleting nothing
53
+ #
28
54
  def delete_job_by_digest
29
- Scripts.call(
30
- :delete_job_by_digest,
31
- nil,
32
- keys: ["#{QUEUE_KEY}:#{queue}", SCHEDULE_SET, RETRY_SET], argv: [unique_digest],
33
- )
55
+ call_script(:delete_job_by_digest,
56
+ keys: ["#{QUEUE}:#{queue}", SCHEDULE, RETRY],
57
+ argv: [unique_digest])
34
58
  end
35
59
 
60
+ #
36
61
  # Delete the keys belonging to the job
62
+ #
63
+ #
64
+ # @return [Integer] the number of keys deleted
65
+ #
37
66
  def delete_lock
38
- SidekiqUniqueJobs::Digests.delete_by_digest(unique_digest)
67
+ call_script(:delete_by_digest, keys: [unique_digest, DIGESTS])
39
68
  end
40
69
  end
41
70
  end
@@ -9,15 +9,15 @@ module SidekiqUniqueJobs
9
9
  include SidekiqUniqueJobs::SidekiqWorkerMethods
10
10
 
11
11
  # @param [Hash] item sidekiq job hash
12
- def initialize(item)
13
- super
14
- @worker_class = item[CLASS_KEY]
12
+ def initialize(item, redis_pool = nil)
13
+ super(item, redis_pool)
14
+ @worker_class = item[CLASS]
15
15
  end
16
16
 
17
17
  # Create a new job from the current one.
18
18
  # This will mess up sidekiq stats because a new job is created
19
19
  def call
20
- worker_class&.perform_in(5, *item[ARGS_KEY]) if sidekiq_worker_class?
20
+ worker_class&.perform_in(5, *item[ARGS]) if sidekiq_worker_class?
21
21
  end
22
22
  end
23
23
  end
@@ -7,15 +7,27 @@ module SidekiqUniqueJobs
7
7
  # @abstract
8
8
  # @author Mikael Henriksson <mikael@zoolutions.se>
9
9
  class Strategy
10
+ include SidekiqUniqueJobs::JSON
10
11
  include SidekiqUniqueJobs::Logging
12
+ include SidekiqUniqueJobs::Script::Caller
13
+ include SidekiqUniqueJobs::Timing
11
14
 
12
- # The sidekiq job hash
13
- # @return [Hash] the Sidekiq job hash
15
+ # @!attribute [r] item
16
+ # @return [Hash] sidekiq job hash
14
17
  attr_reader :item
18
+ # @!attribute [r] redis_pool
19
+ # @return [Sidekiq::RedisConnection, ConnectionPool, NilClass] the redis connection
20
+ attr_reader :redis_pool
15
21
 
16
- # @param [Hash] item the Sidekiq job hash
17
- def initialize(item)
18
- @item = item
22
+ #
23
+ # Initialize a new Strategy
24
+ #
25
+ # @param [Hash] item sidekiq job hash
26
+ # @param [ConnectionPool] redis_pool the connection pool instance
27
+ #
28
+ def initialize(item, redis_pool = nil)
29
+ @item = item
30
+ @redis_pool = redis_pool
19
31
  end
20
32
 
21
33
  # Use strategy on conflict
@@ -24,6 +36,13 @@ module SidekiqUniqueJobs
24
36
  raise NotImplementedError, "needs to be implemented in child class"
25
37
  end
26
38
 
39
+ #
40
+ # Check if the strategy is kind of {Replace}
41
+ #
42
+ #
43
+ # @return [true] when the strategy is a {Replace}
44
+ # @return [false] when the strategy is not a {Replace}
45
+ #
27
46
  def replace?
28
47
  is_a?(Replace)
29
48
  end
@@ -9,24 +9,19 @@ module SidekiqUniqueJobs
9
9
  # 3. worker_class (required, can be anything)
10
10
  # @author Mikael Henriksson <mikael@zoolutions.se>
11
11
  module OptionsWithFallback
12
- LOCKS = {
13
- until_and_while_executing: SidekiqUniqueJobs::Lock::UntilAndWhileExecuting,
14
- until_executed: SidekiqUniqueJobs::Lock::UntilExecuted,
15
- until_executing: SidekiqUniqueJobs::Lock::UntilExecuting,
16
- until_expired: SidekiqUniqueJobs::Lock::UntilExpired,
17
- until_timeout: SidekiqUniqueJobs::Lock::UntilExpired,
18
- while_executing: SidekiqUniqueJobs::Lock::WhileExecuting,
19
- while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject,
20
- }.freeze
21
-
22
12
  def self.included(base)
23
13
  base.send(:include, SidekiqUniqueJobs::SidekiqWorkerMethods)
24
14
  end
25
15
 
16
+ # A convenience method for using the configured locks
17
+ def locks
18
+ SidekiqUniqueJobs.locks
19
+ end
20
+
26
21
  # Check if unique has been enabled
27
22
  # @return [true, false] indicate if the gem has been enabled
28
23
  def unique_enabled?
29
- SidekiqUniqueJobs.config.enabled && lock_type
24
+ SidekiqUniqueJobs.enabled? && lock_type
30
25
  end
31
26
 
32
27
  # Check if unique has been disabled
@@ -34,36 +29,65 @@ module SidekiqUniqueJobs
34
29
  !unique_enabled?
35
30
  end
36
31
 
37
- # Check if we should log duplicate payloads
38
- def log_duplicate_payload?
39
- options[LOG_DUPLICATE_KEY] || item[LOG_DUPLICATE_KEY]
32
+ # Should duplicate payloads be logged?
33
+ #
34
+ #
35
+ # @return [true, false, nil]
36
+ #
37
+ def log_duplicate?
38
+ options[LOG_DUPLICATE] || item[LOG_DUPLICATE]
40
39
  end
41
40
 
42
- # Check if we should log duplicate payloads
43
- # @return [SidekiqUniqueJobs::Lock::BaseLock] an instance of a child class
44
- def lock
45
- @lock ||= lock_class.new(item, after_unlock_hook, @redis_pool)
41
+ #
42
+ # A new lock for this Sidekiq Job
43
+ #
44
+ #
45
+ # @return [Lock::BaseLock] an instance of a lock implementation
46
+ #
47
+ def lock_instance
48
+ @lock_instance ||= lock_class.new(item, after_unlock_hook, @redis_pool)
46
49
  end
47
50
 
48
- # Check if we should log duplicate payloads
49
- # @return [SidekiqUniqueJobs::Lock::BaseLock] an instance of a child class
51
+ #
52
+ # Returns the corresponding class for the lock_type
53
+ #
54
+ #
55
+ # @return [Class]
56
+ #
50
57
  def lock_class
51
58
  @lock_class ||= begin
52
- LOCKS.fetch(lock_type.to_sym) do
59
+ locks.fetch(lock_type.to_sym) do
53
60
  raise UnknownLock, "No implementation for `lock: :#{lock_type}`"
54
61
  end
55
62
  end
56
63
  end
57
64
 
65
+ #
66
+ # The type of lock for this worker
67
+ #
68
+ #
58
69
  # @return [Symbol]
70
+ #
59
71
  def lock_type
60
- @lock_type ||= item[LOCK_KEY] || options[LOCK_KEY] || unique_type
72
+ @lock_type ||= options[LOCK] || item[LOCK] || unique_type
61
73
  end
62
74
 
75
+ #
76
+ # @deprecated in favour of {lock_type}
77
+ #
78
+ #
79
+ # @return [Symbol]
80
+ #
63
81
  def unique_type
64
- options[UNIQUE_KEY] || item[UNIQUE_KEY]
82
+ options[UNIQUE] || item[UNIQUE]
65
83
  end
66
84
 
85
+ #
86
+ # The default options with any matching keys overridden from worker options
87
+ #
88
+ #
89
+ # @return [Hash<String, Object>]
90
+ #
67
91
  def options
68
92
  @options ||= begin
69
93
  opts = default_worker_options.dup