sidekiq-unique-jobs 7.0.0.beta9 → 7.0.0.beta10

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -13
  3. data/lib/sidekiq_unique_jobs.rb +4 -2
  4. data/lib/sidekiq_unique_jobs/batch_delete.rb +2 -0
  5. data/lib/sidekiq_unique_jobs/cli.rb +7 -1
  6. data/lib/sidekiq_unique_jobs/config.rb +47 -3
  7. data/lib/sidekiq_unique_jobs/constants.rb +2 -0
  8. data/lib/sidekiq_unique_jobs/exceptions.rb +12 -7
  9. data/lib/sidekiq_unique_jobs/job.rb +32 -11
  10. data/lib/sidekiq_unique_jobs/lock/base_lock.rb +4 -4
  11. data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +1 -1
  12. data/lib/sidekiq_unique_jobs/lock/validator.rb +22 -0
  13. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +1 -1
  14. data/lib/sidekiq_unique_jobs/lock_args.rb +118 -0
  15. data/lib/sidekiq_unique_jobs/lock_config.rb +26 -1
  16. data/lib/sidekiq_unique_jobs/lock_digest.rb +77 -0
  17. data/lib/sidekiq_unique_jobs/lock_timeout.rb +62 -0
  18. data/lib/sidekiq_unique_jobs/{time_calculator.rb → lock_ttl.rb} +22 -37
  19. data/lib/sidekiq_unique_jobs/locksmith.rb +5 -3
  20. data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +1 -1
  21. data/lib/sidekiq_unique_jobs/middleware.rb +1 -1
  22. data/lib/sidekiq_unique_jobs/on_conflict/log.rb +1 -1
  23. data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +7 -1
  24. data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +2 -2
  25. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +1 -11
  26. data/lib/sidekiq_unique_jobs/orphans/reaper.rb +9 -1
  27. data/lib/sidekiq_unique_jobs/rspec/matchers.rb +5 -0
  28. data/lib/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options.rb +9 -1
  29. data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +17 -5
  30. data/lib/sidekiq_unique_jobs/testing.rb +15 -7
  31. data/lib/sidekiq_unique_jobs/unlockable.rb +3 -3
  32. data/lib/sidekiq_unique_jobs/upgrade_locks.rb +4 -0
  33. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  34. data/lib/sidekiq_unique_jobs/version_check.rb +1 -1
  35. data/lib/sidekiq_unique_jobs/web.rb +1 -1
  36. data/lib/sidekiq_unique_jobs/web/helpers.rb +6 -4
  37. data/lib/sidekiq_unique_jobs/web/views/lock.erb +2 -2
  38. data/lib/tasks/changelog.rake +2 -2
  39. metadata +23 -15
  40. data/lib/sidekiq_unique_jobs/unique_args.rb +0 -148
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a24246a99460117c9ebacb054dc8d1860e3a330058f3c4f34d409125136ffc22
4
- data.tar.gz: 662a626190317ed24ecc5453a936437824166bf5b08cbb9e96187bb63f1d091b
3
+ metadata.gz: 80989f0c409c7ac687e7164fbd31255f566b80543887c899e3c5a50301ee8bc7
4
+ data.tar.gz: 78e4513aa3686ec123d5e63266249a13b4fb05a2087c11ff7c40bd51d951b7a6
5
5
  SHA512:
6
- metadata.gz: a406b1f3f3f73a39f4c50b44417cbc1b6a83492c5e5c4dea71055cda9eca8c5139e667d2a1d4363e952f07e4e918b96455734cfd6285a753cdf3af026c2ab7eb
7
- data.tar.gz: 99742c266e02ef86cfefd96a3c694b986f6d5610fca49877b7fd0f5d14ddcef4abadb6e65ae00b53de1fe71830d74210a9f7ff3237e3aecb141f9c9c5efdcf30
6
+ metadata.gz: 2ad61ee12ab5c62367fea9dfb0dd8850b4580b7cdb8548d370e79da6f164e1201fc5de4019173bc3cae47519814f7a1712c79a0cb5a9c65edd05bd9827e9bc9b
7
+ data.tar.gz: 24aa2c29b9f5097538c70132140d34c92b31a464573ab17e951303c8028702461a6f08ca20d375d0e1b5e0a5fd48ef3e4185aef488e467524912f41ff00fdde8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SidekiqUniqueJobs [![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://travis-ci.org/mhenrixon/sidekiq-unique-jobs.png?branch=master)](https://travis-ci.org/mhenrixon/sidekiq-unique-jobs) [![Code Climate](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs.png)](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)
1
+ # SidekiqUniqueJobs [![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://travis-ci.org/mhenrixon/sidekiq-unique-jobs.svg?branch=master)](https://travis-ci.org/mhenrixon/sidekiq-unique-jobs) [![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)
2
2
 
3
3
  <!-- MarkdownTOC -->
4
4
 
@@ -23,8 +23,8 @@
23
23
  - [Worker Configuration](#worker-configuration)
24
24
  - [lock_ttl](#lock_ttl-1)
25
25
  - [lock_timeout](#lock_timeout-1)
26
- - [unique_across_queues](#uniqueacrossqueues)
27
- - [unique_across_workers](#uniqueacrossworkers)
26
+ - [unique_across_queues](#unique_across_queues)
27
+ - [unique_across_workers](#unique_across_workers)
28
28
  - [Locks](#locks)
29
29
  - [Until Executing](#until-executing)
30
30
  - [Until Executed](#until-executed)
@@ -33,14 +33,14 @@
33
33
  - [While Executing](#while-executing)
34
34
  - [Custom Locks](#custom-locks)
35
35
  - [Conflict Strategy](#conflict-strategy)
36
- - [lib/strategies/my_custom_strategy.rb](#libstrategiesmycustomstrategyrb)
36
+ - [lib/strategies/my_custom_strategy.rb](#libstrategiesmy_custom_strategyrb)
37
37
  - [For rails application](#for-rails-application)
38
- - [config/initializers/sidekiq_unique_jobs.rb](#configinitializerssidekiquniquejobsrb)
38
+ - [config/initializers/sidekiq_unique_jobs.rb](#configinitializerssidekiq_unique_jobsrb)
39
39
  - [For other projects, whenever you prefer](#for-other-projects-whenever-you-prefer)
40
40
  - [this goes in your initializer](#this-goes-in-your-initializer)
41
41
  - [app/config/routes.rb](#appconfigroutesrb)
42
42
  - [app/workers/bad_worker.rb](#appworkersbad_workerrb)
43
- - [spec/workers/bad_worker_spec.rb](#specworkersbadworkerspecrb)
43
+ - [spec/workers/bad_worker_spec.rb](#specworkersbad_worker_specrb)
44
44
  - [OR](#or)
45
45
  - [Contributing](#contributing)
46
46
  - [Contributors](#contributors)
@@ -504,9 +504,9 @@ Requiring the gem in your gemfile should be sufficient to enable unique jobs.
504
504
 
505
505
  ### Finer Control over Uniqueness
506
506
 
507
- Sometimes it is desired to have a finer control over which arguments are used in determining uniqueness of the job, and others may be _transient_. For this use-case, you need to define either a `unique_args` method, or a ruby proc.
507
+ Sometimes it is desired to have a finer control over which arguments are used in determining uniqueness of the job, and others may be _transient_. For this use-case, you need to define either a `lock_args` method, or a ruby proc.
508
508
 
509
- *NOTE:* The unique_args method need to return an array of values to use for uniqueness check.
509
+ *NOTE:* The lock_args method need to return an array of values to use for uniqueness check.
510
510
 
511
511
  *NOTE:* The arguments passed to the proc or the method is always an array. If your method takes a single array as argument the value of args will be `[[...]]`.
512
512
 
@@ -516,9 +516,9 @@ The method or the proc can return a modified version of args without the transie
516
516
  class UniqueJobWithFilterMethod
517
517
  include Sidekiq::Worker
518
518
  sidekiq_options lock: :until_and_while_executing,
519
- unique_args: :unique_args # this is default and will be used if such a method is defined
519
+ lock_args: :lock_args # this is default and will be used if such a method is defined
520
520
 
521
- def self.unique_args(args)
521
+ def self.lock_args(args)
522
522
  [ args[0], args[2][:type] ]
523
523
  end
524
524
 
@@ -529,7 +529,7 @@ end
529
529
  class UniqueJobWithFilterProc
530
530
  include Sidekiq::Worker
531
531
  sidekiq_options lock: :until_executed,
532
- unique_args: ->(args) { [ args.first ] }
532
+ lock_args: ->(args) { [ args.first ] }
533
533
 
534
534
  ...
535
535
 
@@ -541,9 +541,9 @@ It is possible to ensure different types of unique args based on context. I can'
541
541
  ```ruby
542
542
  class UniqueJobWithFilterMethod
543
543
  include Sidekiq::Worker
544
- sidekiq_options lock: :until_and_while_executing, unique_args: :unique_args
544
+ sidekiq_options lock: :until_and_while_executing, lock_args: :lock_args
545
545
 
546
- def self.unique_args(args)
546
+ def self.lock_args(args)
547
547
  if Sidekiq::ProcessSet.new.size > 1
548
548
  # sidekiq runtime; uniqueness for the object (first arg)
549
549
  args.first
@@ -42,8 +42,10 @@ require "sidekiq_unique_jobs/orphans/observer"
42
42
  require "sidekiq_unique_jobs/orphans/manager"
43
43
  require "sidekiq_unique_jobs/cli"
44
44
  require "sidekiq_unique_jobs/core_ext"
45
- require "sidekiq_unique_jobs/time_calculator"
46
- require "sidekiq_unique_jobs/unique_args"
45
+ require "sidekiq_unique_jobs/lock_timeout"
46
+ require "sidekiq_unique_jobs/lock_ttl"
47
+ require "sidekiq_unique_jobs/lock_args"
48
+ require "sidekiq_unique_jobs/lock_digest"
47
49
  require "sidekiq_unique_jobs/unlockable"
48
50
  require "sidekiq_unique_jobs/key"
49
51
  require "sidekiq_unique_jobs/locksmith"
@@ -11,6 +11,8 @@ module SidekiqUniqueJobs
11
11
  # @return [Integer] the default batch size
12
12
  BATCH_SIZE = 100
13
13
 
14
+ #
15
+ # @return [Array<String>] Supported key suffixes
14
16
  SUFFIXES = %w[
15
17
  QUEUED
16
18
  PRIMED
@@ -9,12 +9,14 @@ module SidekiqUniqueJobs
9
9
  # @author Mikael Henriksson <mikael@zoolutions.se>
10
10
  #
11
11
  class Cli < Thor
12
+ # :nodoc:
12
13
  def self.banner(command, _namespace = nil, _subcommand = false)
13
- "jobs #{@package_name} #{command.usage}"
14
+ "jobs #{@package_name} #{command.usage}" # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
14
15
  end
15
16
 
16
17
  desc "list PATTERN", "list all unique digests and their expiry time"
17
18
  option :count, aliases: :c, type: :numeric, default: 1000, desc: "The max number of digests to return"
19
+ # :nodoc:
18
20
  def list(pattern = "*")
19
21
  entries = digests.entries(pattern: pattern, count: options[:count])
20
22
  say "Found #{entries.size} digests matching '#{pattern}':"
@@ -24,6 +26,7 @@ module SidekiqUniqueJobs
24
26
  desc "del PATTERN", "deletes unique digests from redis by pattern"
25
27
  option :dry_run, aliases: :d, type: :boolean, desc: "set to false to perform deletion"
26
28
  option :count, aliases: :c, type: :numeric, default: 1000, desc: "The max number of digests to return"
29
+ # :nodoc:
27
30
  def del(pattern)
28
31
  max_count = options[:count]
29
32
  if options[:dry_run]
@@ -36,6 +39,7 @@ module SidekiqUniqueJobs
36
39
  end
37
40
 
38
41
  desc "console", "drop into a console with easy access to helper methods"
42
+ # :nodoc:
39
43
  def console
40
44
  say "Use `list '*', 1000 to display the first 1000 unique digests matching '*'"
41
45
  say "Use `del '*', 1000, true (default) to see how many digests would be deleted for the pattern '*'"
@@ -46,10 +50,12 @@ module SidekiqUniqueJobs
46
50
  end
47
51
 
48
52
  no_commands do
53
+ # :nodoc:
49
54
  def digests
50
55
  @digests ||= SidekiqUniqueJobs::Digests.new
51
56
  end
52
57
 
58
+ # :nodoc:
53
59
  def console_class
54
60
  require "pry"
55
61
  Pry
@@ -25,11 +25,15 @@ module SidekiqUniqueJobs
25
25
  #
26
26
  # @author Mauro Berlanda <mauro.berlanda@gmail.com>
27
27
  class Config < ThreadSafeConfig
28
+ #
29
+ # @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available queued locks
28
30
  LOCKS_WHILE_ENQUEUED = {
29
31
  until_executing: SidekiqUniqueJobs::Lock::UntilExecuting,
30
32
  while_enqueued: SidekiqUniqueJobs::Lock::UntilExecuting,
31
33
  }.freeze
32
34
 
35
+ #
36
+ # @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available fulltime locks
33
37
  LOCKS_FROM_PUSH_TO_PROCESSED = {
34
38
  until_completed: SidekiqUniqueJobs::Lock::UntilExecuted,
35
39
  until_executed: SidekiqUniqueJobs::Lock::UntilExecuted,
@@ -39,10 +43,14 @@ module SidekiqUniqueJobs
39
43
  until_successfully_completed: SidekiqUniqueJobs::Lock::UntilExecuted,
40
44
  }.freeze
41
45
 
46
+ #
47
+ # @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available locks without unlock
42
48
  LOCKS_WITHOUT_UNLOCK = {
43
49
  until_expired: SidekiqUniqueJobs::Lock::UntilExpired,
44
50
  }.freeze
45
51
 
52
+ #
53
+ # @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available runtime/client locks
46
54
  LOCKS_WHEN_BUSY = {
47
55
  around_perform: SidekiqUniqueJobs::Lock::WhileExecuting,
48
56
  while_busy: SidekiqUniqueJobs::Lock::WhileExecuting,
@@ -51,6 +59,8 @@ module SidekiqUniqueJobs
51
59
  while_executing_reject: SidekiqUniqueJobs::Lock::WhileExecutingReject,
52
60
  }.freeze
53
61
 
62
+ #
63
+ # @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available default locks
54
64
  LOCKS =
55
65
  LOCKS_WHEN_BUSY.dup
56
66
  .merge(LOCKS_WHILE_ENQUEUED.dup)
@@ -58,6 +68,8 @@ module SidekiqUniqueJobs
58
68
  .merge(LOCKS_FROM_PUSH_TO_PROCESSED.dup)
59
69
  .freeze
60
70
 
71
+ #
72
+ # @return [Hash<Symbol, SidekiqUniqueJobs::OnConflict::Strategy] all available default strategies
61
73
  STRATEGIES = {
62
74
  log: SidekiqUniqueJobs::OnConflict::Log,
63
75
  raise: SidekiqUniqueJobs::OnConflict::Raise,
@@ -66,18 +78,44 @@ module SidekiqUniqueJobs
66
78
  reschedule: SidekiqUniqueJobs::OnConflict::Reschedule,
67
79
  }.freeze
68
80
 
81
+ #
82
+ # @return ['uniquejobs'] by default we use this prefix
69
83
  PREFIX = "uniquejobs"
84
+ #
85
+ # @return [0] by default don't wait for locks
70
86
  LOCK_TIMEOUT = 0
87
+ #
88
+ # @return [nil]
71
89
  LOCK_TTL = nil
90
+ #
91
+ # @return [true] by default the gem is enabled
72
92
  ENABLED = true
93
+ #
94
+ # @return [false] by default we don't debug the lua scripts because it is slow
73
95
  DEBUG_LUA = false
96
+ #
97
+ # @return [1_000] use a changelog history of 1_000 entries by default
74
98
  MAX_HISTORY = 1_000
75
- REAPER = :ruby # The type of cleanup to run. Possible values are [:ruby, :lua]
99
+ #
100
+ # @return [:ruby] prefer the ruby reaper by default since the lua reaper still has problems
101
+ REAPER = :ruby
102
+ #
103
+ # @return [1_000] reap 1_000 orphaned locks at a time by default
76
104
  REAPER_COUNT = 1_000
77
- REAPER_INTERVAL = 600 # Every 10 minutes
78
- REAPER_TIMEOUT = 10 # 10 seconds
105
+ #
106
+ # @return [600] reap locks every 10 minutes
107
+ REAPER_INTERVAL = 600
108
+ #
109
+ # @return [10] stop reaper after 10 seconds
110
+ REAPER_TIMEOUT = 10
111
+ #
112
+ # @return [false] while useful it also adds overhead so disable lock_info by default
79
113
  USE_LOCK_INFO = false
114
+ #
115
+ # @return [false] by default we don't raise validation errors for workers
80
116
  RAISE_ON_CONFIG_ERROR = false
117
+ #
118
+ # @return [0.0.0] default redis version is only to avoid NoMethodError on nil
81
119
  REDIS_VERSION = "0.0.0"
82
120
 
83
121
  #
@@ -185,6 +223,12 @@ module SidekiqUniqueJobs
185
223
  self.strategies = new_strategies
186
224
  end
187
225
 
226
+ #
227
+ # The current version of redis
228
+ #
229
+ #
230
+ # @return [String] a version string eg. `5.0.1`
231
+ #
188
232
  def redis_version
189
233
  self.current_redis_version = SidekiqUniqueJobs.fetch_redis_version if current_redis_version == REDIS_VERSION
190
234
  current_redis_version
@@ -17,6 +17,8 @@ module SidekiqUniqueJobs
17
17
  LIMIT ||= "limit"
18
18
  LIVE_VERSION ||= "uniquejobs:live"
19
19
  LOCK ||= "lock"
20
+ LOCK_ARGS ||= "lock_args"
21
+ LOCK_DIGEST ||= "lock_digest"
20
22
  LOCK_EXPIRATION ||= "lock_expiration"
21
23
  LOCK_INFO ||= "lock_info"
22
24
  LOCK_LIMIT ||= "lock_limit"
@@ -14,7 +14,7 @@ module SidekiqUniqueJobs
14
14
  # @author Mikael Henriksson <mikael@zoolutions.se>
15
15
  class Conflict < UniqueJobsError
16
16
  def initialize(item)
17
- super("Item with the key: #{item[UNIQUE_DIGEST]} is already scheduled or processing")
17
+ super("Item with the key: #{item[LOCK_DIGEST]} is already scheduled or processing")
18
18
  end
19
19
  end
20
20
 
@@ -60,13 +60,18 @@ module SidekiqUniqueJobs
60
60
  #
61
61
  # @author Mikael Henriksson <mikael@zoolutions.se>
62
62
  class InvalidUniqueArguments < UniqueJobsError
63
- def initialize(given:, worker_class:, unique_args_method:)
64
- uniq_args_meth = worker_class.method(unique_args_method)
65
- num_args = uniq_args_meth.arity
66
- # source_location = uniq_args_meth.source_location
63
+ def initialize(options)
64
+ given = options[:given]
65
+ worker_class = options[:worker_class]
66
+ lock_args_method = options[:lock_args_method]
67
+ lock_args_meth = worker_class.method(lock_args_method)
68
+ num_args = lock_args_meth.arity
69
+ source_location = lock_args_meth.source_location
67
70
 
68
71
  super(
69
- "#{worker_class}#unique_args takes #{num_args} arguments, received #{given.inspect}"
72
+ "#{worker_class}##{lock_args_method} takes #{num_args} arguments, received #{given.inspect}" \
73
+ "\n\n" \
74
+ " #{source_location.join(':')}"
70
75
  )
71
76
  end
72
77
  end
@@ -77,7 +82,7 @@ module SidekiqUniqueJobs
77
82
  # @author Mikael Henriksson <mikael@zoolutions.se>
78
83
  #
79
84
  class NotUniqueWorker < UniqueJobsError
80
- def initialize(options: {})
85
+ def initialize(options)
81
86
  super("#{options[:class]} is not configured for uniqueness. Missing the key `:lock` in #{options.inspect}")
82
87
  end
83
88
  end
@@ -7,23 +7,44 @@ module SidekiqUniqueJobs
7
7
  module Job
8
8
  extend self
9
9
 
10
- # Adds timeout, expiration, unique_args, unique_prefix and unique_digest to the sidekiq job hash
11
- # @return [void] nothing returned here matters
12
- def add_uniqueness(item)
13
- add_timeout_and_expiration(item)
14
- add_unique_args_and_digest(item)
10
+ # Adds timeout, expiration, lock_args, lock_prefix and lock_digest to the sidekiq job hash
11
+ # @return [Hash] the job hash
12
+ def prepare(item)
13
+ add_lock_timeout(item)
14
+ add_lock_ttl(item)
15
+ add_digest(item)
16
+ end
17
+
18
+ # Adds lock_args, lock_prefix and lock_digest to the sidekiq job hash
19
+ # @return [Hash] the job hash
20
+ def add_digest(item)
21
+ add_lock_prefix(item)
22
+ add_lock_args(item)
23
+ add_lock_digest(item)
24
+
25
+ item
15
26
  end
16
27
 
17
28
  private
18
29
 
19
- def add_timeout_and_expiration(item)
20
- calculator = SidekiqUniqueJobs::TimeCalculator.new(item)
21
- item[LOCK_TIMEOUT] = calculator.lock_timeout
22
- item[LOCK_TTL] = calculator.lock_ttl
30
+ def add_lock_ttl(item)
31
+ item[LOCK_TTL] = SidekiqUniqueJobs::LockTTL.calculate(item)
32
+ end
33
+
34
+ def add_lock_timeout(item)
35
+ item[LOCK_TIMEOUT] = SidekiqUniqueJobs::LockTimeout.calculate(item)
36
+ end
37
+
38
+ def add_lock_args(item)
39
+ item[LOCK_ARGS] = SidekiqUniqueJobs::LockArgs.call(item)
40
+ end
41
+
42
+ def add_lock_digest(item)
43
+ item[LOCK_DIGEST] = SidekiqUniqueJobs::LockDigest.call(item)
23
44
  end
24
45
 
25
- def add_unique_args_and_digest(item)
26
- SidekiqUniqueJobs::UniqueArgs.digest(item)
46
+ def add_lock_prefix(item)
47
+ item[LOCK_PREFIX] = SidekiqUniqueJobs.config.unique_prefix
27
48
  end
28
49
  end
29
50
  end
@@ -28,7 +28,7 @@ module SidekiqUniqueJobs
28
28
  @callback = callback
29
29
  @redis_pool = redis_pool
30
30
  @attempt = 0
31
- add_uniqueness_when_missing # Used to ease testing
31
+ prepare_item # Used to ease testing
32
32
  @lock_config = LockConfig.new(item)
33
33
  end
34
34
 
@@ -90,12 +90,12 @@ module SidekiqUniqueJobs
90
90
 
91
91
  private
92
92
 
93
- def add_uniqueness_when_missing
94
- return if item.key?(UNIQUE_DIGEST)
93
+ def prepare_item
94
+ return if item.key?(LOCK_DIGEST)
95
95
 
96
96
  # The below should only be done to ease testing
97
97
  # in production this will be done by the middleware
98
- SidekiqUniqueJobs::Job.add_uniqueness(item)
98
+ SidekiqUniqueJobs::Job.prepare(item)
99
99
  end
100
100
 
101
101
  def call_strategy
@@ -21,7 +21,7 @@ module SidekiqUniqueJobs
21
21
  runtime_lock.execute { return yield }
22
22
  end
23
23
  else
24
- log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST]} #{item[JID]}"
24
+ log_warn "couldn't unlock digest: #{item[LOCK_DIGEST]} #{item[JID]}"
25
25
  end
26
26
  end
27
27
 
@@ -8,6 +8,12 @@ module SidekiqUniqueJobs
8
8
  # @author Mikael Henriksson <mikael@zoolutions.se>
9
9
  #
10
10
  class Validator
11
+ DEPRECATED_KEYS = {
12
+ UNIQUE.to_sym => LOCK.to_sym,
13
+ UNIQUE_ARGS.to_sym => LOCK_ARGS.to_sym,
14
+ UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym,
15
+ }.freeze
16
+
11
17
  #
12
18
  # Shorthand for `new(options).validate`
13
19
  #
@@ -30,7 +36,9 @@ module SidekiqUniqueJobs
30
36
  # @param [Hash] options the sidekiq_options for the worker being validated
31
37
  #
32
38
  def initialize(options)
39
+ @options = options.transform_keys(&:to_sym)
33
40
  @lock_config = LockConfig.new(options)
41
+ handle_deprecations
34
42
  end
35
43
 
36
44
  #
@@ -53,10 +61,24 @@ module SidekiqUniqueJobs
53
61
  lock_config
54
62
  end
55
63
 
64
+ def handle_deprecations
65
+ DEPRECATED_KEYS.each do |old, new|
66
+ next unless @options.key?(old)
67
+
68
+ lock_config.errors[old] = "is deprecated, use `#{new}: #{@options[old]}` instead."
69
+ end
70
+ end
71
+
72
+ #
73
+ # Validates the client configuration
74
+ #
56
75
  def validate_client
57
76
  ClientValidator.validate(lock_config)
58
77
  end
59
78
 
79
+ #
80
+ # Validates the server configuration
81
+ #
60
82
  def validate_server
61
83
  ServerValidator.validate(lock_config)
62
84
  end