From 89caa5e406a1f4bfb86c13d3d8a2658df5b7875b Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 21 Mar 2020 14:26:43 +0100 Subject: [PATCH 1/5] Rename remaining unique_* keys to lock_* --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- README.md | 24 +++---- bin/bench | 2 +- lib/sidekiq_unique_jobs/constants.rb | 2 + lib/sidekiq_unique_jobs/exceptions.rb | 18 ++--- lib/sidekiq_unique_jobs/job.rb | 24 +++---- lib/sidekiq_unique_jobs/lock/base_lock.rb | 2 +- .../lock/until_and_while_executing.rb | 2 +- .../lock/while_executing.rb | 2 +- lib/sidekiq_unique_jobs/lock_args.rb | 58 +++++++-------- lib/sidekiq_unique_jobs/lock_digest.rb | 26 +++---- lib/sidekiq_unique_jobs/locksmith.rb | 4 +- .../logging/middleware_context.rb | 2 +- lib/sidekiq_unique_jobs/middleware.rb | 2 +- lib/sidekiq_unique_jobs/on_conflict/log.rb | 2 +- .../on_conflict/replace.rb | 2 +- .../on_conflict/reschedule.rb | 4 +- lib/sidekiq_unique_jobs/web/helpers.rb | 2 +- lib/sidekiq_unique_jobs/web/views/lock.erb | 4 +- myapp/app/lib/lock_simulator.rb | 2 +- myapp/config/initializers/sidekiq.rb | 2 +- spec/performance/lock_digest_spec.rb | 16 ++--- spec/performance/locksmith_spec.rb | 2 +- spec/sidekiq/api_spec.rb | 10 +-- spec/sidekiq/retry_set_spec.rb | 2 +- spec/sidekiq_unique_jobs/cli_spec.rb | 2 +- .../sidekiq_unique_jobs/configuration_spec.rb | 2 +- spec/sidekiq_unique_jobs/digests_spec.rb | 22 +++--- spec/sidekiq_unique_jobs/job_spec.rb | 6 +- .../lock/until_expired_spec.rb | 1 - spec/sidekiq_unique_jobs/lock_args_spec.rb | 70 ++++++++++--------- spec/sidekiq_unique_jobs/lock_digest_spec.rb | 26 +++---- spec/sidekiq_unique_jobs/lock_spec.rb | 2 +- spec/sidekiq_unique_jobs/locksmith_spec.rb | 2 +- .../lua/delete_job_by_digest_spec.rb | 2 +- .../lua/reap_orphans_spec.rb | 4 +- .../middleware/client_spec.rb | 4 +- .../middleware/server_spec.rb | 2 +- .../on_conflict/log_spec.rb | 10 +-- .../on_conflict/raise_spec.rb | 2 +- .../on_conflict/replace_spec.rb | 12 ++-- .../on_conflict/reschedule_spec.rb | 2 +- .../on_conflict/strategy_spec.rb | 2 +- .../orphans/reaper_spec.rb | 4 +- .../custom_queue_job_with_filter_method.rb | 2 +- .../custom_queue_job_with_filter_proc.rb | 2 +- .../my_unique_job_with_filter_method.rb | 2 +- .../workers/my_unique_job_with_filter_proc.rb | 2 +- spec/support/workers/simple_worker.rb | 2 +- .../unique_job_with_conditional_parameter.rb | 2 +- .../workers/unique_job_with_filter_method.rb | 2 +- .../unique_job_with_nil_unique_args.rb | 2 +- .../unique_job_with_no_unique_args_method.rb | 2 +- ...nique_job_without_unique_args_parameter.rb | 2 +- ...ustom_queue_job_with_filter_method_spec.rb | 2 +- .../custom_queue_job_with_filter_proc_spec.rb | 2 +- .../my_unique_job_with_filter_method_spec.rb | 2 +- .../my_unique_job_with_filter_proc_spec.rb | 4 +- spec/workers/simple_worker_spec.rb | 4 +- .../unique_job_with_nil_unique_args_spec.rb | 2 +- ...que_job_with_no_unique_args_method_spec.rb | 2 +- ..._job_without_unique_args_parameter_spec.rb | 2 +- 62 files changed, 222 insertions(+), 213 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c482ff2ce..c99f1400f 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -21,7 +21,7 @@ class MyWorker sidekiq_options lock: :until_executed, queue: :undefault def perform(args); end - def self.unique_args(args) + def self.lock_args(args) # the way you consider unique arguments end end diff --git a/README.md b/README.md index 5320fb8aa..e08780e26 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ - [Worker Configuration](#worker-configuration) - [lock_ttl](#lock_ttl-1) - [lock_timeout](#lock_timeout-1) - - [unique_across_queues](#uniqueacrossqueues) - - [unique_across_workers](#uniqueacrossworkers) + - [unique_across_queues](#unique_across_queues) + - [unique_across_workers](#unique_across_workers) - [Locks](#locks) - [Until Executing](#until-executing) - [Until Executed](#until-executed) @@ -33,14 +33,14 @@ - [While Executing](#while-executing) - [Custom Locks](#custom-locks) - [Conflict Strategy](#conflict-strategy) -- [lib/strategies/my_custom_strategy.rb](#libstrategiesmycustomstrategyrb) +- [lib/strategies/my_custom_strategy.rb](#libstrategiesmy_custom_strategyrb) - [For rails application](#for-rails-application) -- [config/initializers/sidekiq_unique_jobs.rb](#configinitializerssidekiquniquejobsrb) +- [config/initializers/sidekiq_unique_jobs.rb](#configinitializerssidekiq_unique_jobsrb) - [For other projects, whenever you prefer](#for-other-projects-whenever-you-prefer) - [this goes in your initializer](#this-goes-in-your-initializer) - [app/config/routes.rb](#appconfigroutesrb) - [app/workers/bad_worker.rb](#appworkersbad_workerrb) -- [spec/workers/bad_worker_spec.rb](#specworkersbadworkerspecrb) +- [spec/workers/bad_worker_spec.rb](#specworkersbad_worker_specrb) - [OR](#or) - [Contributing](#contributing) - [Contributors](#contributors) @@ -504,9 +504,9 @@ Requiring the gem in your gemfile should be sufficient to enable unique jobs. ### Finer Control over Uniqueness -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. +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. -*NOTE:* The unique_args method need to return an array of values to use for uniqueness check. +*NOTE:* The lock_args method need to return an array of values to use for uniqueness check. *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 `[[...]]`. @@ -516,9 +516,9 @@ The method or the proc can return a modified version of args without the transie class UniqueJobWithFilterMethod include Sidekiq::Worker sidekiq_options lock: :until_and_while_executing, - unique_args: :unique_args # this is default and will be used if such a method is defined + lock_args: :lock_args # this is default and will be used if such a method is defined - def self.unique_args(args) + def self.lock_args(args) [ args[0], args[2][:type] ] end @@ -529,7 +529,7 @@ end class UniqueJobWithFilterProc include Sidekiq::Worker sidekiq_options lock: :until_executed, - unique_args: ->(args) { [ args.first ] } + lock_args: ->(args) { [ args.first ] } ... @@ -541,9 +541,9 @@ It is possible to ensure different types of unique args based on context. I can' ```ruby class UniqueJobWithFilterMethod include Sidekiq::Worker - sidekiq_options lock: :until_and_while_executing, unique_args: :unique_args + sidekiq_options lock: :until_and_while_executing, lock_args: :lock_args - def self.unique_args(args) + def self.lock_args(args) if Sidekiq::ProcessSet.new.size > 1 # sidekiq runtime; uniqueness for the object (first arg) args.first diff --git a/bin/bench b/bin/bench index b181fe0ba..032e18923 100755 --- a/bin/bench +++ b/bin/bench @@ -31,7 +31,7 @@ def get_item(num) "args" => [num, num], "queue" => QUEUES.sample, "jid" => JOB_IDS[num], - "unique_digest" => DIGESTS[num] } + "lock_digest" => DIGESTS[num] } end Benchmark.ips do |ips| diff --git a/lib/sidekiq_unique_jobs/constants.rb b/lib/sidekiq_unique_jobs/constants.rb index 5e6633da0..9b9f92e4f 100644 --- a/lib/sidekiq_unique_jobs/constants.rb +++ b/lib/sidekiq_unique_jobs/constants.rb @@ -17,6 +17,8 @@ module SidekiqUniqueJobs LIMIT ||= "limit" LIVE_VERSION ||= "uniquejobs:live" LOCK ||= "lock" + LOCK_ARGS ||= "lock_args" + LOCK_DIGEST ||= "lock_digest" LOCK_EXPIRATION ||= "lock_expiration" LOCK_INFO ||= "lock_info" LOCK_LIMIT ||= "lock_limit" diff --git a/lib/sidekiq_unique_jobs/exceptions.rb b/lib/sidekiq_unique_jobs/exceptions.rb index 14eced69b..1b2dec3d1 100644 --- a/lib/sidekiq_unique_jobs/exceptions.rb +++ b/lib/sidekiq_unique_jobs/exceptions.rb @@ -14,7 +14,7 @@ class UniqueJobsError < ::RuntimeError # @author Mikael Henriksson class Conflict < UniqueJobsError def initialize(item) - super("Item with the key: #{item[UNIQUE_DIGEST]} is already scheduled or processing") + super("Item with the key: #{item[LOCK_DIGEST]} is already scheduled or processing") end end @@ -61,15 +61,17 @@ def initialize(lock_config) # @author Mikael Henriksson class InvalidUniqueArguments < UniqueJobsError def initialize(options) - given = options[:given] - worker_class = options[:worker_class] - unique_args_method = options[:unique_args_method] - uniq_args_meth = worker_class.method(unique_args_method) - num_args = uniq_args_meth.arity - # source_location = uniq_args_meth.source_location + given = options[:given] + worker_class = options[:worker_class] + lock_args_method = options[:lock_args_method] + lock_args_meth = worker_class.method(lock_args_method) + num_args = lock_args_meth.arity + source_location = lock_args_meth.source_location super( - "#{worker_class}#unique_args takes #{num_args} arguments, received #{given.inspect}" + "#{worker_class}##{lock_args_method} takes #{num_args} arguments, received #{given.inspect}" \ + "\n\n" \ + " #{source_location.join(':')}" ) end end diff --git a/lib/sidekiq_unique_jobs/job.rb b/lib/sidekiq_unique_jobs/job.rb index 6cfe754ce..7763c5b63 100644 --- a/lib/sidekiq_unique_jobs/job.rb +++ b/lib/sidekiq_unique_jobs/job.rb @@ -7,22 +7,20 @@ module SidekiqUniqueJobs module Job extend self - # Adds timeout, expiration, unique_args, unique_prefix and unique_digest to the sidekiq job hash + # Adds timeout, expiration, lock_args, lock_prefix and lock_digest to the sidekiq job hash # @return [Hash] the job hash def prepare(item) add_lock_timeout(item) add_lock_ttl(item) add_digest(item) - - item end - # Adds unique_args, unique_prefix and unique_digest to the sidekiq job hash + # Adds lock_args, lock_prefix and lock_digest to the sidekiq job hash # @return [Hash] the job hash def add_digest(item) - add_unique_prefix(item) - add_unique_args(item) - add_unique_digest(item) + add_lock_prefix(item) + add_lock_args(item) + add_lock_digest(item) item end @@ -37,16 +35,16 @@ def add_lock_timeout(item) item[LOCK_TIMEOUT] = SidekiqUniqueJobs::LockTimeout.calculate(item) end - def add_unique_args(item) - item[UNIQUE_ARGS] = SidekiqUniqueJobs::LockArgs.call(item) + def add_lock_args(item) + item[LOCK_ARGS] = SidekiqUniqueJobs::LockArgs.call(item) end - def add_unique_digest(item) - item[UNIQUE_DIGEST] = SidekiqUniqueJobs::LockDigest.call(item) + def add_lock_digest(item) + item[LOCK_DIGEST] = SidekiqUniqueJobs::LockDigest.call(item) end - def add_unique_prefix(item) - item[UNIQUE_PREFIX] = SidekiqUniqueJobs.config.unique_prefix + def add_lock_prefix(item) + item[LOCK_PREFIX] = SidekiqUniqueJobs.config.unique_prefix end end end diff --git a/lib/sidekiq_unique_jobs/lock/base_lock.rb b/lib/sidekiq_unique_jobs/lock/base_lock.rb index 3a746d84c..5638e132e 100644 --- a/lib/sidekiq_unique_jobs/lock/base_lock.rb +++ b/lib/sidekiq_unique_jobs/lock/base_lock.rb @@ -91,7 +91,7 @@ def locksmith private def prepare_item - return if item.key?(UNIQUE_DIGEST) + return if item.key?(LOCK_DIGEST) # The below should only be done to ease testing # in production this will be done by the middleware diff --git a/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb b/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb index 22c88b409..93c1768bd 100644 --- a/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +++ b/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb @@ -21,7 +21,7 @@ def execute runtime_lock.execute { return yield } end else - log_warn "couldn't unlock digest: #{item[UNIQUE_DIGEST]} #{item[JID]}" + log_warn "couldn't unlock digest: #{item[LOCK_DIGEST]} #{item[JID]}" end end diff --git a/lib/sidekiq_unique_jobs/lock/while_executing.rb b/lib/sidekiq_unique_jobs/lock/while_executing.rb index cccfd03de..caecd7afc 100644 --- a/lib/sidekiq_unique_jobs/lock/while_executing.rb +++ b/lib/sidekiq_unique_jobs/lock/while_executing.rb @@ -51,7 +51,7 @@ def execute # This is safe as the base_lock always creates a new digest # The append there for needs to be done every time def append_unique_key_suffix - item[UNIQUE_DIGEST] = item[UNIQUE_DIGEST] + RUN_SUFFIX + item[LOCK_DIGEST] = item[LOCK_DIGEST] + RUN_SUFFIX end end end diff --git a/lib/sidekiq_unique_jobs/lock_args.rb b/lib/sidekiq_unique_jobs/lock_args.rb index df33a42a4..69f3f1cc2 100644 --- a/lib/sidekiq_unique_jobs/lock_args.rb +++ b/lib/sidekiq_unique_jobs/lock_args.rb @@ -13,7 +13,7 @@ class LockArgs # @param [Hash] item a Sidekiq job hash # @return [String] a unique digest def self.call(item) - new(item).unique_args + new(item).lock_args end # The sidekiq job hash @@ -32,42 +32,42 @@ def initialize(item) end # The unique arguments to use for creating a lock - # @return [Array] the arguments filters by the {#filtered_args} method if {#unique_args_enabled?} - def unique_args - @unique_args ||= filtered_args + # @return [Array] the arguments filters by the {#filtered_args} method if {#lock_args_enabled?} + def lock_args + @lock_args ||= filtered_args end - # Checks if the worker class has enabled unique_args + # Checks if the worker class has enabled lock_args # @return [true, false] - def unique_args_enabled? - # return false unless unique_args_method_valid? + def lock_args_enabled? + # return false unless lock_args_method_valid? - unique_args_method + lock_args_method end - # Validate that the unique_args_method is acceptable + # Validate that the lock_args_method is acceptable # @return [true, false] - def unique_args_method_valid? - [NilClass, TrueClass, FalseClass].none? { |klass| unique_args_method.is_a?(klass) } + def lock_args_method_valid? + [NilClass, TrueClass, FalseClass].none? { |klass| lock_args_method.is_a?(klass) } end - # Checks if the worker class has disabled unique_args + # Checks if the worker class has disabled lock_args # @return [true, false] - def unique_args_disabled? - !unique_args_method + def lock_args_disabled? + !lock_args_method end # Filters unique arguments by proc or symbol - # @return [Array] {#filter_by_proc} when {#unique_args_method} is a Proc - # @return [Array] {#filter_by_symbol} when {#unique_args_method} is a Symbol + # @return [Array] {#filter_by_proc} when {#lock_args_method} is a Proc + # @return [Array] {#filter_by_symbol} when {#lock_args_method} is a Symbol # @return [Array] args unfiltered when neither of the above def filtered_args - return args if unique_args_disabled? + return args if lock_args_disabled? return args if args.empty? json_args = Normalizer.jsonify(args) - case unique_args_method + case lock_args_method when Proc filter_by_proc(json_args) when Symbol @@ -79,7 +79,7 @@ def filtered_args # @param [Array] args the arguments passed to the sidekiq worker # @return [Array] with the filtered arguments def filter_by_proc(args) - unique_args_method.call(args) + lock_args_method.call(args) end # Filters unique arguments by method configured in the sidekiq worker @@ -87,26 +87,28 @@ def filter_by_proc(args) # @return [Array] unfiltered unless {#worker_method_defined?} # @return [Array] with the filtered arguments def filter_by_symbol(args) - return args unless worker_method_defined?(unique_args_method) + return args unless worker_method_defined?(lock_args_method) - worker_class.send(unique_args_method, args) + worker_class.send(lock_args_method, args) rescue ArgumentError raise SidekiqUniqueJobs::InvalidUniqueArguments, given: args, worker_class: worker_class, - unique_args_method: unique_args_method + lock_args_method: lock_args_method end # The method to use for filtering unique arguments - def unique_args_method - @unique_args_method ||= worker_options[UNIQUE_ARGS] - @unique_args_method ||= :unique_args if worker_method_defined?(:unique_args) - @unique_args_method ||= default_unique_args_method + def lock_args_method + @lock_args_method ||= worker_options[LOCK_ARGS] || worker_options[UNIQUE_ARGS] + @lock_args_method ||= :lock_args if worker_method_defined?(:lock_args) + @lock_args_method ||= :unique_args if worker_method_defined?(:unique_args) + @lock_args_method ||= default_lock_args_method end # The global worker options defined in Sidekiq directly - def default_unique_args_method - Sidekiq.default_worker_options.stringify_keys[UNIQUE_ARGS] + def default_lock_args_method + Sidekiq.default_worker_options.stringify_keys[LOCK_ARGS] || + Sidekiq.default_worker_options.stringify_keys[UNIQUE_ARGS] end end end diff --git a/lib/sidekiq_unique_jobs/lock_digest.rb b/lib/sidekiq_unique_jobs/lock_digest.rb index e95fc8029..ed1bd2ad7 100644 --- a/lib/sidekiq_unique_jobs/lock_digest.rb +++ b/lib/sidekiq_unique_jobs/lock_digest.rb @@ -17,7 +17,7 @@ class LockDigest # @return [String] a unique digest for the given arguments # def self.call(item) - new(item).unique_digest + new(item).lock_digest end # The sidekiq job hash @@ -26,37 +26,37 @@ def self.call(item) # # @!attribute [r] args # @return [Array] the arguments passed to `perform_async` - attr_reader :unique_args + attr_reader :lock_args # # @!attribute [r] args # @return [String] the prefix for the unique key - attr_reader :unique_prefix + attr_reader :lock_prefix # @param [Hash] item a Sidekiq job hash def initialize(item) - @item = item - @worker_class = item[CLASS] - @unique_args = item[UNIQUE_ARGS] - @unique_prefix = item[UNIQUE_PREFIX] + @item = item + @worker_class = item[CLASS] + @lock_args = item[LOCK_ARGS] || item[UNIQUE_ARGS] # TODO: Deprecate UNIQUE_ARGS + @lock_prefix = item[LOCK_PREFIX] || item[UNIQUE_PREFIX] # TODO: Deprecate UNIQUE_PREFIX end - # Memoized unique_digest + # Memoized lock_digest # @return [String] a unique digest - def unique_digest - @unique_digest ||= create_digest + def lock_digest + @lock_digest ||= create_digest end - # Creates a namespaced unique digest based on the {#digestable_hash} and the {#unique_prefix} + # Creates a namespaced unique digest based on the {#digestable_hash} and the {#lock_prefix} # @return [String] a unique digest def create_digest digest = ::Digest::MD5.hexdigest(dump_json(digestable_hash)) - "#{unique_prefix}:#{digest}" + "#{lock_prefix}:#{digest}" end # Filter a hash to use for digest # @return [Hash] to use for digest def digestable_hash - @item.slice(CLASS, QUEUE, UNIQUE_ARGS).tap do |hash| + @item.slice(CLASS, QUEUE, LOCK_ARGS).tap do |hash| hash.delete(QUEUE) if unique_across_queues? hash.delete(CLASS) if unique_across_workers? end diff --git a/lib/sidekiq_unique_jobs/locksmith.rb b/lib/sidekiq_unique_jobs/locksmith.rb index 1855e0e88..001156e55 100644 --- a/lib/sidekiq_unique_jobs/locksmith.rb +++ b/lib/sidekiq_unique_jobs/locksmith.rb @@ -57,7 +57,7 @@ class Locksmith # rubocop:disable Metrics/ClassLength # def initialize(item, redis_pool = nil) @item = item - @key = Key.new(item[UNIQUE_DIGEST]) + @key = Key.new(item[LOCK_DIGEST] || item[UNIQUE_DIGEST]) # fallback until can be removed @job_id = item[JID] @config = LockConfig.new(item) @redis_pool = redis_pool @@ -341,7 +341,7 @@ def lock_info TIMEOUT => item[LOCK_TIMEOUT], TTL => item[LOCK_TTL], LOCK => config.type, - UNIQUE_ARGS => item[UNIQUE_ARGS], + LOCK_ARGS => item[LOCK_ARGS], TIME => now_f, ) end diff --git a/lib/sidekiq_unique_jobs/logging/middleware_context.rb b/lib/sidekiq_unique_jobs/logging/middleware_context.rb index 842e03e42..0b1aa4b8f 100644 --- a/lib/sidekiq_unique_jobs/logging/middleware_context.rb +++ b/lib/sidekiq_unique_jobs/logging/middleware_context.rb @@ -30,7 +30,7 @@ def self.included(base) # def logging_context middleware = is_a?(SidekiqUniqueJobs::Middleware::Client) ? :client : :server - digest = item[UNIQUE_DIGEST] + digest = item[LOCK_DIGEST] lock_type = item[LOCK] if logger_context_hash? diff --git a/lib/sidekiq_unique_jobs/middleware.rb b/lib/sidekiq_unique_jobs/middleware.rb index 2da39a1c6..3a2a37517 100644 --- a/lib/sidekiq_unique_jobs/middleware.rb +++ b/lib/sidekiq_unique_jobs/middleware.rb @@ -80,7 +80,7 @@ def call(worker_class, item, queue, redis_pool = nil) @redis_pool = redis_pool return yield if unique_disabled? - SidekiqUniqueJobs::Job.prepare(item) unless item[UNIQUE_DIGEST] + SidekiqUniqueJobs::Job.prepare(item) unless item[LOCK_DIGEST] with_logging_context do super diff --git a/lib/sidekiq_unique_jobs/on_conflict/log.rb b/lib/sidekiq_unique_jobs/on_conflict/log.rb index c74b80361..0833123f8 100644 --- a/lib/sidekiq_unique_jobs/on_conflict/log.rb +++ b/lib/sidekiq_unique_jobs/on_conflict/log.rb @@ -16,7 +16,7 @@ class Log < OnConflict::Strategy # def call log_info(<<~MESSAGE.chomp) - Skipping job with id (#{item[JID]}) because unique_digest: (#{item[UNIQUE_DIGEST]}) already exists + Skipping job with id (#{item[JID]}) because lock_digest: (#{item[LOCK_DIGEST]}) already exists MESSAGE end end diff --git a/lib/sidekiq_unique_jobs/on_conflict/replace.rb b/lib/sidekiq_unique_jobs/on_conflict/replace.rb index 1a6a9f841..4ebbafe97 100644 --- a/lib/sidekiq_unique_jobs/on_conflict/replace.rb +++ b/lib/sidekiq_unique_jobs/on_conflict/replace.rb @@ -23,7 +23,7 @@ class Replace < OnConflict::Strategy def initialize(item, redis_pool = nil) super(item, redis_pool) @queue = item[QUEUE] - @unique_digest = item[UNIQUE_DIGEST] + @unique_digest = item[LOCK_DIGEST] end # diff --git a/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb b/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb index 04d6cba2f..539494523 100644 --- a/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +++ b/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb @@ -20,10 +20,10 @@ def initialize(item, redis_pool = nil) # This will mess up sidekiq stats because a new job is created def call if sidekiq_worker_class? - log_info("Rescheduling #{item[UNIQUE_DIGEST]}") + log_info("Rescheduling #{item[LOCK_DIGEST]}") worker_class&.perform_in(5, *item[ARGS]) else - log_warn("Skip rescheduling of #{item[UNIQUE_DIGEST]} because #{worker_class} is not a Sidekiq::Worker") + log_warn("Skip rescheduling of #{item[LOCK_DIGEST]} because #{worker_class} is not a Sidekiq::Worker") end end end diff --git a/lib/sidekiq_unique_jobs/web/helpers.rb b/lib/sidekiq_unique_jobs/web/helpers.rb index 3924e540c..25b7bba4d 100644 --- a/lib/sidekiq_unique_jobs/web/helpers.rb +++ b/lib/sidekiq_unique_jobs/web/helpers.rb @@ -65,7 +65,7 @@ def cparams(options) # # @return [String] a string containing all non-truncated arguments # - def display_unique_args(args, truncate_after_chars = 2000) + def display_lock_args(args, truncate_after_chars = 2000) return "Invalid job payload, args is nil" if args.nil? return "Invalid job payload, args must be an Array, not #{args.class.name}" unless args.is_a?(Array) diff --git a/lib/sidekiq_unique_jobs/web/views/lock.erb b/lib/sidekiq_unique_jobs/web/views/lock.erb index acc9c3fa7..fe8dd7aea 100644 --- a/lib/sidekiq_unique_jobs/web/views/lock.erb +++ b/lib/sidekiq_unique_jobs/web/views/lock.erb @@ -35,11 +35,11 @@ <%= @lock.info["timeout"] %> - <%= t('Unique Args') %> + <%= t('Args') %> -
<%= display_unique_args(@lock.info["unique_args"], nil) %>
+
<%= display_lock_args(@lock.info["lock_args"], nil) %>
diff --git a/myapp/app/lib/lock_simulator.rb b/myapp/app/lib/lock_simulator.rb index 07fbad390..3b915f71b 100644 --- a/myapp/app/lib/lock_simulator.rb +++ b/myapp/app/lib/lock_simulator.rb @@ -47,7 +47,7 @@ def create_v7_locks(num = 20) # rubocop:disable Metrics/MethodLength "timeout" => rand(20), "ttl" => nil, "lock" => SidekiqUniqueJobs.locks.keys.sample, - "unique_args" => UNIQUE_ARGS.sample(2), + "lock_args" => UNIQUE_ARGS.sample(2), "time" => now_f, )) end diff --git a/myapp/config/initializers/sidekiq.rb b/myapp/config/initializers/sidekiq.rb index 585f5c0e6..2e5b39585 100644 --- a/myapp/config/initializers/sidekiq.rb +++ b/myapp/config/initializers/sidekiq.rb @@ -20,7 +20,7 @@ config.error_handlers << ->(ex, ctx_hash) { p ex, ctx_hash } config.death_handlers << lambda do |job, _ex| - digest = job["unique_digest"] + digest = job["lock_digest"] SidekiqUniqueJobs::Digests.delete_by_digest(digest) if digest end diff --git a/spec/performance/lock_digest_spec.rb b/spec/performance/lock_digest_spec.rb index 83117898b..8ffa4d95a 100644 --- a/spec/performance/lock_digest_spec.rb +++ b/spec/performance/lock_digest_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SidekiqUniqueJobs::LockDigest, perf: true do - let(:unique_args) { described_class.new(item) } + let(:lock_digest) { described_class.new(item) } let(:worker_class) { UntilExecutedJob } let(:class_name) { worker_class.to_s } let(:queue) { "myqueue" } @@ -14,20 +14,20 @@ } end - describe "#unique_digest" do - subject(:unique_digest) { unique_args.unique_digest } + describe "#lock_digest" do + subject(:lock_digest) { lock_digest.lock_digest } it "performs in under 0.1 ms" do - expect { unique_digest }.to perform_under(0.1).ms + expect { lock_digest }.to perform_under(0.1).ms end context "when args are empty" do - let(:another_unique_args) { described_class.new(item) } + let(:another_lock_digest) { described_class.new(item) } let(:worker_class) { WithoutArgumentJob } let(:args) { [] } it "performs in under 0.1 ms" do - expect { unique_digest }.to perform_under(0.1).ms + expect { lock_digest }.to perform_under(0.1).ms end end @@ -36,7 +36,7 @@ let(:args) { [1, 2, "type" => "it"] } it "performs in under 0.1 ms" do - expect { unique_digest }.to perform_under(0.1).ms + expect { lock_digest }.to perform_under(0.1).ms end end @@ -45,7 +45,7 @@ let(:args) { [1, 2, "type" => "it"] } it "performs in under 0.1 ms" do - expect { unique_digest }.to perform_under(0.1).ms + expect { lock_digest }.to perform_under(0.1).ms end end end diff --git a/spec/performance/locksmith_spec.rb b/spec/performance/locksmith_spec.rb index e88ec9f26..90b57737b 100644 --- a/spec/performance/locksmith_spec.rb +++ b/spec/performance/locksmith_spec.rb @@ -16,7 +16,7 @@ let(:item_one) do { "jid" => jid_one, - "unique_digest" => digest, + "lock_digest" => digest, "lock_ttl" => lock_ttl, "lock" => lock_type, "lock_timeout" => lock_timeout, diff --git a/spec/sidekiq/api_spec.rb b/spec/sidekiq/api_spec.rb index f07e5bb5e..69df06482 100644 --- a/spec/sidekiq/api_spec.rb +++ b/spec/sidekiq/api_spec.rb @@ -6,8 +6,8 @@ "queue" => "testqueue", "args" => [foo: "bar"] } end - let(:unique_digest) { "uniquejobs:863b7cb639bd71c828459b97788b2ada" } - let(:key) { SidekiqUniqueJobs::Key.new(unique_digest) } + let(:lock_digest) { "uniquejobs:577db3c4fc72230bf2c256faa708a083" } + let(:key) { SidekiqUniqueJobs::Key.new(lock_digest) } describe Sidekiq::SortedEntry::UniqueExtension do it "deletes uniqueness lock on delete" do @@ -37,9 +37,9 @@ "queue" => "testqueue", "retry" => true, "lock" => "until_executed", - "unique_args" => [{ "foo" => "bar" }], - "unique_digest" => key.digest, - "unique_prefix" => "uniquejobs", + "lock_args" => [{ "foo" => "bar" }], + "lock_digest" => key.digest, + "lock_prefix" => "uniquejobs", ), ) end diff --git a/spec/sidekiq/retry_set_spec.rb b/spec/sidekiq/retry_set_spec.rb index d3141e2df..bd4def2bb 100644 --- a/spec/sidekiq/retry_set_spec.rb +++ b/spec/sidekiq/retry_set_spec.rb @@ -22,7 +22,7 @@ "queue" => queue, "retry_at" => retry_at, "retry_count" => 1, - "unique_digest" => unique_digest, + "lock_digest" => unique_digest, } end diff --git a/spec/sidekiq_unique_jobs/cli_spec.rb b/spec/sidekiq_unique_jobs/cli_spec.rb index 7f64a04cb..4a108ff23 100644 --- a/spec/sidekiq_unique_jobs/cli_spec.rb +++ b/spec/sidekiq_unique_jobs/cli_spec.rb @@ -7,7 +7,7 @@ let(:item) do { "jid" => jid, - "unique_digest" => digest, + "lock_digest" => digest, } end let(:jid) { "abcdefab" } diff --git a/spec/sidekiq_unique_jobs/configuration_spec.rb b/spec/sidekiq_unique_jobs/configuration_spec.rb index 5774aefdd..237707dcc 100644 --- a/spec/sidekiq_unique_jobs/configuration_spec.rb +++ b/spec/sidekiq_unique_jobs/configuration_spec.rb @@ -31,7 +31,7 @@ def lock let(:ttl) { nil } let(:item) do { - "unique_digest" => digest, + "lock_digest" => digest, "jid" => jid, "lock_expiration" => ttl, "lock" => lock_type, diff --git a/spec/sidekiq_unique_jobs/digests_spec.rb b/spec/sidekiq_unique_jobs/digests_spec.rb index 01b853b25..94ed349ec 100644 --- a/spec/sidekiq_unique_jobs/digests_spec.rb +++ b/spec/sidekiq_unique_jobs/digests_spec.rb @@ -4,16 +4,16 @@ let(:digests) { described_class.new } let(:expected_keys) do { - "uniquejobs:e739dadc23533773b920936336341d01" => kind_of(Float), - "uniquejobs:56c68cab5038eb57959538866377560d" => kind_of(Float), - "uniquejobs:8d9e83be14c033be4496295ec2740b91" => kind_of(Float), - "uniquejobs:23e8715233c2e8f7b578263fcb8ac657" => kind_of(Float), - "uniquejobs:6722965def15faf3c45cb9e66f994a49" => kind_of(Float), - "uniquejobs:5bdd20fbbdda2fc28d6461e0eb1f76ee" => kind_of(Float), - "uniquejobs:c658060a30b761bb12f2133cb7c3f294" => kind_of(Float), - "uniquejobs:b34294c4802ee2d61c9e3e8dd7f2bab4" => kind_of(Float), - "uniquejobs:06c3a5b63038c7b724b8603bb02ace99" => kind_of(Float), - "uniquejobs:62c11d32fd69c691802579682409a483" => kind_of(Float), + "uniquejobs:0781b1f587a9a8d08773f21ed752caed" => kind_of(Float), + "uniquejobs:09b3a42f77a75865bf27ac44e66bb4ef" => kind_of(Float), + "uniquejobs:1c4c0bf2a8a1006c7610e4ef1f965f34" => kind_of(Float), + "uniquejobs:236feda848cfbb1ae32d4d9af666349e" => kind_of(Float), + "uniquejobs:77d1e23f18943bc048b48a01b85af0b3" => kind_of(Float), + "uniquejobs:9fcaaf3e873f101a8d79e00e89bb3b36" => kind_of(Float), + "uniquejobs:a47040c19b3741eaf912a96cd8bee728" => kind_of(Float), + "uniquejobs:c85f45d715232cfff0505fb85ca92659" => kind_of(Float), + "uniquejobs:cb5be91a66b83435281c23fe489f22b5" => kind_of(Float), + "uniquejobs:e74bebbf569d620397688fded62c85d6" => kind_of(Float), } end @@ -32,7 +32,7 @@ describe "#delete_by_digest" do subject(:delete_by_digest) { digests.delete_by_digest(digest) } - let(:digest) { "uniquejobs:62c11d32fd69c691802579682409a483" } + let(:digest) { "uniquejobs:e74bebbf569d620397688fded62c85d6" } before do allow(digests).to receive(:log_info) diff --git a/spec/sidekiq_unique_jobs/job_spec.rb b/spec/sidekiq_unique_jobs/job_spec.rb index 348025c56..004653d76 100644 --- a/spec/sidekiq_unique_jobs/job_spec.rb +++ b/spec/sidekiq_unique_jobs/job_spec.rb @@ -23,9 +23,9 @@ "args" => [1, 2], "lock_timeout" => MyUniqueJob.get_sidekiq_options["lock_timeout"].to_i, "lock_ttl" => MyUniqueJob.get_sidekiq_options["lock_ttl"], - "unique_args" => args, - "unique_digest" => "uniquejobs:77b7db49e1339ec4bda2addf1e74aae0", - "unique_prefix" => "uniquejobs", + "lock_args" => args, + "lock_digest" => "uniquejobs:149ef752a5776e0bd05929b8f0e33250", + "lock_prefix" => "uniquejobs", }, ) end diff --git a/spec/sidekiq_unique_jobs/lock/until_expired_spec.rb b/spec/sidekiq_unique_jobs/lock/until_expired_spec.rb index b266d18f7..08bba9da8 100644 --- a/spec/sidekiq_unique_jobs/lock/until_expired_spec.rb +++ b/spec/sidekiq_unique_jobs/lock/until_expired_spec.rb @@ -41,7 +41,6 @@ process_one.lock process_one.execute {} expect(process_one).to be_locked - expect("uniquejobs:da6005926a8457526e998f0033901dfc").to have_ttl(1) end end diff --git a/spec/sidekiq_unique_jobs/lock_args_spec.rb b/spec/sidekiq_unique_jobs/lock_args_spec.rb index d612058c7..c52f75e0c 100644 --- a/spec/sidekiq_unique_jobs/lock_args_spec.rb +++ b/spec/sidekiq_unique_jobs/lock_args_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SidekiqUniqueJobs::LockArgs do - let(:unique_args) { described_class.new(item) } + let(:lock_args) { described_class.new(item) } let(:worker_class) { UntilExecutedJob } let(:class_name) { worker_class.to_s } let(:queue) { "myqueue" } @@ -14,36 +14,36 @@ } end - describe "#unique_args_enabled?" do - subject(:unique_args_enabled?) { unique_args.unique_args_enabled? } + describe "#lock_args_enabled?" do + subject(:lock_args_enabled?) { lock_args.lock_args_enabled? } context "with default worker options", :with_sidekiq_options do - let(:sidekiq_options) { { unique: :until_executed, unique_args: ->(args) { args[1]["test"] } } } + let(:sidekiq_options) { { unique: :until_executed, lock_args: ->(args) { args[1]["test"] } } } - context "when `unique_args: :unique_args` in worker", :with_worker_options do - let(:worker_options) { { unique_args: :unique_args } } + context "when `lock_args: :lock_args` in worker", :with_worker_options do + let(:worker_options) { { lock_args: :lock_args } } - it { is_expected.to eq(:unique_args) } + it { is_expected.to eq(:lock_args) } end - context "when `unique_args: false` in worker", :with_worker_options do - let(:worker_options) { { unique_args: false } } + context "when `lock_args: false` in worker", :with_worker_options do + let(:worker_options) { { lock_args: false } } it { is_expected.to be_a(Proc) } end end context "when disabled in default_worker_options", :with_sidekiq_options do - let(:sidekiq_options) { { unique: false, unique_args: nil } } + let(:sidekiq_options) { { unique: false, lock_args: nil } } - context "when `unique_args: :unique_args` in worker", :with_worker_options do - let(:worker_options) { { unique_args: :unique_args } } + context "when `lock_args: :lock_args` in worker", :with_worker_options do + let(:worker_options) { { lock_args: :lock_args } } - it { is_expected.to eq(:unique_args) } + it { is_expected.to eq(:lock_args) } end - context "when `unique_args: false` in worker", :with_worker_options do - let(:worker_options) { { unique_args: false } } + context "when `lock_args: false` in worker", :with_worker_options do + let(:worker_options) { { lock_args: false } } it { is_expected.to eq(nil) } end @@ -51,13 +51,13 @@ end describe "#filtered_args" do - subject(:filtered_args) { unique_args.filtered_args } + subject(:filtered_args) { lock_args.filtered_args } let(:args) { [1, "test" => "it"] } - context "when #unique_args_method is nil" do + context "when #lock_args_method is nil" do before do - allow(unique_args).to receive(:unique_args_method).and_return(nil) + allow(lock_args).to receive(:lock_args_method).and_return(nil) end it { is_expected.to eq(args) } @@ -65,21 +65,21 @@ end describe "#filter_by_proc" do - subject(:filter_by_proc) { unique_args.filter_by_proc(args) } + subject(:filter_by_proc) { lock_args.filter_by_proc(args) } let(:args) { [1, "test" => "it"] } - context "when #unique_args_method is a proc" do + context "when #lock_args_method is a proc" do let(:filter) { ->(args) { args[1]["test"] } } - before { allow(unique_args).to receive(:unique_args_method).and_return(filter) } + before { allow(lock_args).to receive(:lock_args_method).and_return(filter) } it { is_expected.to eq("it") } end context "when configured globally" do it "uses global filter" do - Sidekiq.use_options(unique_args: ->(args) { args.first }) do + Sidekiq.use_options(lock_args: ->(args) { args.first }) do expect(filter_by_proc).to eq(1) end end @@ -87,7 +87,7 @@ end describe "#filter_by_symbol" do - subject(:filter_by_symbol) { unique_args.filter_by_symbol(args) } + subject(:filter_by_symbol) { lock_args.filter_by_symbol(args) } context "when filter is a working symbol" do let(:worker_class) { UniqueJobWithFilterMethod } @@ -105,8 +105,10 @@ expect { filter_by_symbol } .to raise_error( SidekiqUniqueJobs::InvalidUniqueArguments, - "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ - " received [1]", + a_string_starting_with( + "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ + " received [1]", + ) ) end @@ -117,14 +119,16 @@ expect { filter_by_symbol } .to raise_error( SidekiqUniqueJobs::InvalidUniqueArguments, - "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ - " received []", + a_string_starting_with( + "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ + " received []", + ) ) end end end - context "when workers unique_args method doesn't take parameters" do + context "when workers lock_args method doesn't take parameters" do let(:worker_class) { UniqueJobWithoutUniqueArgsParameter } let(:args) { ["name", 2, "whatever" => nil, "type" => "test"] } @@ -132,20 +136,22 @@ expect { filter_by_symbol } .to raise_error( SidekiqUniqueJobs::InvalidUniqueArguments, - 'UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments,' \ - ' received ["name", 2, {"whatever"=>nil, "type"=>"test"}]', + a_string_starting_with( + 'UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments,' \ + ' received ["name", 2, {"whatever"=>nil, "type"=>"test"}]' \ + ) ) end end - context "when @worker_class does not respond_to unique_args_method" do + context "when @worker_class does not respond_to lock_args_method" do let(:worker_class) { UniqueJobWithNoUniqueArgsMethod } let(:args) { ["name", 2, "whatever" => nil, "type" => "test"] } it { is_expected.to eq(args) } end - context "when workers unique_args method returns nil" do + context "when workers lock_args method returns nil" do let(:worker_class) { UniqueJobWithNilUniqueArgs } let(:args) { ["name", 2, "whatever" => nil, "type" => "test"] } diff --git a/spec/sidekiq_unique_jobs/lock_digest_spec.rb b/spec/sidekiq_unique_jobs/lock_digest_spec.rb index 06755b840..fe17b152e 100644 --- a/spec/sidekiq_unique_jobs/lock_digest_spec.rb +++ b/spec/sidekiq_unique_jobs/lock_digest_spec.rb @@ -10,12 +10,12 @@ { "class" => class_name, "queue" => queue, - "unique_args" => args, + "lock_args" => args, } end - describe "#unique_digest" do - subject(:unique_digest) { digest.unique_digest } + describe "#lock_digest" do + subject(:lock_digest) { digest.lock_digest } context "when args are empty" do let(:digest_two) { described_class.new(item) } @@ -23,8 +23,8 @@ let(:args) { [] } context "with the same unique args" do - it "equals to unique_digest for that item" do - expect(unique_digest).to eq(digest_two.unique_digest) + it "equals to lock_digest for that item" do + expect(lock_digest).to eq(digest_two.lock_digest) end end end @@ -36,16 +36,16 @@ context "with the same unique args" do let(:another_item) { item } - it "equals to unique_digest for that item" do - expect(unique_digest).to eq(digest_two.unique_digest) + it "equals to lock_digest for that item" do + expect(lock_digest).to eq(digest_two.lock_digest) end end context "with different unique args" do - let(:another_item) { item.merge("unique_args" => [1, 3, "type" => "that"]) } + let(:another_item) { item.merge("lock_args" => [1, 3, "type" => "that"]) } - it "differs from unique_digest for that item" do - expect(unique_digest).not_to eq(digest_two.unique_digest) + it "differs from lock_digest for that item" do + expect(lock_digest).not_to eq(digest_two.lock_digest) end end end @@ -69,18 +69,18 @@ describe "#digestable_hash" do subject(:digestable_hash) { digest.digestable_hash } - it { is_expected.to eq("class" => "UntilExecutedJob", "queue" => "myqueue", "unique_args" => [[1, 2]]) } + it { is_expected.to eq("class" => "UntilExecutedJob", "queue" => "myqueue", "lock_args" => [[1, 2]]) } context "when unique_across_queues", :with_worker_options do let(:worker_options) { { unique_across_queues: true } } - it { is_expected.to eq("class" => "UntilExecutedJob", "unique_args" => [[1, 2]]) } + it { is_expected.to eq("class" => "UntilExecutedJob", "lock_args" => [[1, 2]]) } end context "when unique_across_workers", :with_worker_options do let(:worker_options) { { unique_across_workers: true } } - it { is_expected.to eq("queue" => "myqueue", "unique_args" => [[1, 2]]) } + it { is_expected.to eq("queue" => "myqueue", "lock_args" => [[1, 2]]) } end end diff --git a/spec/sidekiq_unique_jobs/lock_spec.rb b/spec/sidekiq_unique_jobs/lock_spec.rb index 83cbeaa3e..89b991ad1 100644 --- a/spec/sidekiq_unique_jobs/lock_spec.rb +++ b/spec/sidekiq_unique_jobs/lock_spec.rb @@ -27,7 +27,7 @@ timeout: 10, ttl: 2, lock: :until_executed, - unique_args: [1, 2], + lock_args: [1, 2], time: SidekiqUniqueJobs.now_f, } end diff --git a/spec/sidekiq_unique_jobs/locksmith_spec.rb b/spec/sidekiq_unique_jobs/locksmith_spec.rb index d057f0d50..506ed592b 100644 --- a/spec/sidekiq_unique_jobs/locksmith_spec.rb +++ b/spec/sidekiq_unique_jobs/locksmith_spec.rb @@ -16,7 +16,7 @@ let(:item_one) do { "jid" => jid_one, - "unique_digest" => digest, + "lock_digest" => digest, "lock_ttl" => lock_ttl, "lock" => lock_type, "lock_timeout" => lock_timeout, diff --git a/spec/sidekiq_unique_jobs/lua/delete_job_by_digest_spec.rb b/spec/sidekiq_unique_jobs/lua/delete_job_by_digest_spec.rb index ee25460b2..3e46dc399 100644 --- a/spec/sidekiq_unique_jobs/lua/delete_job_by_digest_spec.rb +++ b/spec/sidekiq_unique_jobs/lua/delete_job_by_digest_spec.rb @@ -29,7 +29,7 @@ "jid" => job_id, "retry_count" => 2, "failed_at" => Time.now.to_f, - "unique_digest" => digest, + "lock_digest" => digest, } end diff --git a/spec/sidekiq_unique_jobs/lua/reap_orphans_spec.rb b/spec/sidekiq_unique_jobs/lua/reap_orphans_spec.rb index 1d8e53844..e3aa763a7 100644 --- a/spec/sidekiq_unique_jobs/lua/reap_orphans_spec.rb +++ b/spec/sidekiq_unique_jobs/lua/reap_orphans_spec.rb @@ -21,7 +21,7 @@ let(:lock) { SidekiqUniqueJobs::Lock.create(digest, job_id, lock_info) } let(:job_id) { "job_id" } let(:item) { raw_item } - let(:raw_item) { { "class" => MyUniqueJob, "args" => [1, 2], "jid" => job_id, "unique_digest" => digest } } + let(:raw_item) { { "class" => MyUniqueJob, "args" => [1, 2], "jid" => job_id, "lock_digest" => digest } } let(:lock_info) do { "job_id" => job_id, @@ -30,7 +30,7 @@ "time" => now_f, "timeout" => nil, "ttl" => nil, - "unique_args" => [1, 2], + "lock_args" => [1, 2], "worker" => "MyUniqueJob", } end diff --git a/spec/sidekiq_unique_jobs/middleware/client_spec.rb b/spec/sidekiq_unique_jobs/middleware/client_spec.rb index d4ad7dc70..6ae455eef 100644 --- a/spec/sidekiq_unique_jobs/middleware/client_spec.rb +++ b/spec/sidekiq_unique_jobs/middleware/client_spec.rb @@ -9,7 +9,7 @@ expect(schedule_count).to eq(1) expected = %w[ - uniquejobs:6e47d668ad22db2a3ba0afd331514ce2 + uniquejobs:26a33855311a0a653c5e0b4af1d1458d ] expect(keys).to include(*expected) @@ -101,7 +101,7 @@ context "when filter method is defined" do it "pushes no duplicate messages" do expect(CustomQueueJobWithFilterMethod).to respond_to(:args_filter) - expect(CustomQueueJobWithFilterMethod.get_sidekiq_options["unique_args"]).to eq :args_filter + expect(CustomQueueJobWithFilterMethod.get_sidekiq_options["lock_args"]).to eq :args_filter Array.new(10) do |i| push_item( diff --git a/spec/sidekiq_unique_jobs/middleware/server_spec.rb b/spec/sidekiq_unique_jobs/middleware/server_spec.rb index 5960f7ae2..950773c6c 100644 --- a/spec/sidekiq_unique_jobs/middleware/server_spec.rb +++ b/spec/sidekiq_unique_jobs/middleware/server_spec.rb @@ -11,7 +11,7 @@ jid = UntilExecutedJob.perform_async item = Sidekiq::Queue.new(queue).find_job(jid).item - digest = "uniquejobs:7f28fc7bce5b2f7ea9895080e9b2d282" + digest = "uniquejobs:cf51f14f752c9ca8f3cfb0bbebad4abc" expect(get(digest)).to eq(jid) set(digest, "NOT_DELETED") diff --git a/spec/sidekiq_unique_jobs/on_conflict/log_spec.rb b/spec/sidekiq_unique_jobs/on_conflict/log_spec.rb index 30cd08037..ec13b53fd 100644 --- a/spec/sidekiq_unique_jobs/on_conflict/log_spec.rb +++ b/spec/sidekiq_unique_jobs/on_conflict/log_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true RSpec.describe SidekiqUniqueJobs::OnConflict::Log do - let(:strategy) { described_class.new(item) } - let(:unique_digest) { "uniquejobs:random-digest-value" } - let(:jid) { "arandomjid" } + let(:strategy) { described_class.new(item) } + let(:lock_digest) { "uniquejobs:random-digest-value" } + let(:jid) { "arandomjid" } let(:item) do - { "unique_digest" => unique_digest, "jid" => jid } + { "lock_digest" => lock_digest, "jid" => jid } end describe "#call" do @@ -13,7 +13,7 @@ allow(strategy).to receive(:log_info) strategy.call expect(strategy).to have_received(:log_info).with( - "Skipping job with id (#{jid}) because unique_digest: (#{unique_digest}) already exists", + "Skipping job with id (#{jid}) because lock_digest: (#{lock_digest}) already exists", ) end end diff --git a/spec/sidekiq_unique_jobs/on_conflict/raise_spec.rb b/spec/sidekiq_unique_jobs/on_conflict/raise_spec.rb index 86f3bd44c..55963c565 100644 --- a/spec/sidekiq_unique_jobs/on_conflict/raise_spec.rb +++ b/spec/sidekiq_unique_jobs/on_conflict/raise_spec.rb @@ -4,7 +4,7 @@ let(:strategy) { described_class.new(item) } let(:unique_digest) { "uniquejobs:random-digest-value" } let(:item) do - { "unique_digest" => unique_digest } + { "lock_digest" => unique_digest } end describe "#call" do diff --git a/spec/sidekiq_unique_jobs/on_conflict/replace_spec.rb b/spec/sidekiq_unique_jobs/on_conflict/replace_spec.rb index a9716f9d6..dfc0f58ad 100644 --- a/spec/sidekiq_unique_jobs/on_conflict/replace_spec.rb +++ b/spec/sidekiq_unique_jobs/on_conflict/replace_spec.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true RSpec.describe SidekiqUniqueJobs::OnConflict::Replace do - let(:strategy) { described_class.new(item) } - let(:unique_digest) { "uniquejobs:56c68cab5038eb57959538866377560d" } - let(:block) { -> { p "Hello" } } - let(:digest) { digests.entries.first } + let(:strategy) { described_class.new(item) } + let(:lock_digest) { "uniquejobs:0781b1f587a9a8d08773f21ed752caed" } + let(:block) { -> { p "Hello" } } + let(:digest) { digests.entries.first } let(:item) do - { "unique_digest" => unique_digest, "queue" => :customqueue } + { "lock_digest" => lock_digest, "queue" => :customqueue } end describe "#call" do @@ -30,7 +30,7 @@ "jid" => jid, "retry_count" => 2, "failed_at" => Time.now.to_f, - "unique_digest" => unique_digest, + "lock_digest" => lock_digest, } end diff --git a/spec/sidekiq_unique_jobs/on_conflict/reschedule_spec.rb b/spec/sidekiq_unique_jobs/on_conflict/reschedule_spec.rb index 65549be68..72fee4fd8 100644 --- a/spec/sidekiq_unique_jobs/on_conflict/reschedule_spec.rb +++ b/spec/sidekiq_unique_jobs/on_conflict/reschedule_spec.rb @@ -5,7 +5,7 @@ let(:unique_digest) { "uniquejobs:random-digest-value" } let(:item) do { "class" => UniqueJobOnConflictReschedule, - "unique_digest" => unique_digest, + "lock_digest" => unique_digest, "args" => [1, 2] } end diff --git a/spec/sidekiq_unique_jobs/on_conflict/strategy_spec.rb b/spec/sidekiq_unique_jobs/on_conflict/strategy_spec.rb index aaa5095fc..c62694086 100644 --- a/spec/sidekiq_unique_jobs/on_conflict/strategy_spec.rb +++ b/spec/sidekiq_unique_jobs/on_conflict/strategy_spec.rb @@ -4,7 +4,7 @@ let(:strategy) { described_class.new(item) } let(:unique_digest) { "uniquejobs:56c68cab5038eb57959538866377560d" } let(:item) do - { "unique_digest" => unique_digest, "queue" => :customqueue } + { "lock_digest" => unique_digest, "queue" => :customqueue } end describe "#replace?" do diff --git a/spec/sidekiq_unique_jobs/orphans/reaper_spec.rb b/spec/sidekiq_unique_jobs/orphans/reaper_spec.rb index 64c605bd5..87d751062 100644 --- a/spec/sidekiq_unique_jobs/orphans/reaper_spec.rb +++ b/spec/sidekiq_unique_jobs/orphans/reaper_spec.rb @@ -6,7 +6,7 @@ let(:job_id) { "job_id" } let(:item) { raw_item } let(:lock) { SidekiqUniqueJobs::Lock.create(digest, job_id, lock_info) } - let(:raw_item) { { "class" => MyUniqueJob, "args" => [], "jid" => job_id, "unique_digest" => digest } } + let(:raw_item) { { "class" => MyUniqueJob, "args" => [], "jid" => job_id, "lock_digest" => digest } } let(:lock_info) do { "job_id" => job_id, @@ -15,7 +15,7 @@ "time" => now_f, "timeout" => nil, "ttl" => nil, - "unique_args" => [], + "lock_args" => [], "worker" => "MyUniqueJob", } end diff --git a/spec/support/workers/custom_queue_job_with_filter_method.rb b/spec/support/workers/custom_queue_job_with_filter_method.rb index ac8be5891..3dc666095 100644 --- a/spec/support/workers/custom_queue_job_with_filter_method.rb +++ b/spec/support/workers/custom_queue_job_with_filter_method.rb @@ -5,7 +5,7 @@ require_relative "custom_queue_job" class CustomQueueJobWithFilterMethod < CustomQueueJob - sidekiq_options lock: :until_executed, unique_args: :args_filter + sidekiq_options lock: :until_executed, lock_args: :args_filter def self.args_filter(args) args.first diff --git a/spec/support/workers/custom_queue_job_with_filter_proc.rb b/spec/support/workers/custom_queue_job_with_filter_proc.rb index 34f6d3a02..ffba63968 100644 --- a/spec/support/workers/custom_queue_job_with_filter_proc.rb +++ b/spec/support/workers/custom_queue_job_with_filter_proc.rb @@ -8,7 +8,7 @@ class CustomQueueJobWithFilterProc < CustomQueueJob # slightly contrived example of munging args to the # worker and removing a random bit. sidekiq_options lock: :until_expired, - unique_args: (lambda do |args| + lock_args: (lambda do |args| options = args.extract_options! options.delete("random") args + [options] diff --git a/spec/support/workers/my_unique_job_with_filter_method.rb b/spec/support/workers/my_unique_job_with_filter_method.rb index 42a924f69..7d90475f3 100644 --- a/spec/support/workers/my_unique_job_with_filter_method.rb +++ b/spec/support/workers/my_unique_job_with_filter_method.rb @@ -8,7 +8,7 @@ class MyUniqueJobWithFilterMethod lock: :until_executed, queue: :customqueue, retry: true, - unique_args: :filtered_args + lock_args: :filtered_args def perform(*) # NO-OP diff --git a/spec/support/workers/my_unique_job_with_filter_proc.rb b/spec/support/workers/my_unique_job_with_filter_proc.rb index b1c653faa..1a3c06059 100644 --- a/spec/support/workers/my_unique_job_with_filter_proc.rb +++ b/spec/support/workers/my_unique_job_with_filter_proc.rb @@ -8,7 +8,7 @@ class MyUniqueJobWithFilterProc lock: :until_executed, queue: :customqueue, retry: true, - unique_args: (lambda do |args| + lock_args: (lambda do |args| options = args.extract_options! [args.first, options["type"]] end) diff --git a/spec/support/workers/simple_worker.rb b/spec/support/workers/simple_worker.rb index 8f0db96a0..35659b42d 100644 --- a/spec/support/workers/simple_worker.rb +++ b/spec/support/workers/simple_worker.rb @@ -6,7 +6,7 @@ class SimpleWorker include Sidekiq::Worker sidekiq_options lock: :until_executed, queue: :default, - unique_args: ->(args) { [args.first] } + lock_args: ->(args) { [args.first] } def perform(args) sleep 5 diff --git a/spec/support/workers/unique_job_with_conditional_parameter.rb b/spec/support/workers/unique_job_with_conditional_parameter.rb index becbfda7d..91ef77d68 100644 --- a/spec/support/workers/unique_job_with_conditional_parameter.rb +++ b/spec/support/workers/unique_job_with_conditional_parameter.rb @@ -8,7 +8,7 @@ class UniqueJobWithoutUniqueArgsParameter lock: :until_executed, queue: :customqueue, retry: true, - unique_args: :unique_args + lock_args: :unique_args def perform(conditional = nil) [conditional] diff --git a/spec/support/workers/unique_job_with_filter_method.rb b/spec/support/workers/unique_job_with_filter_method.rb index a94345d01..219797dc7 100644 --- a/spec/support/workers/unique_job_with_filter_method.rb +++ b/spec/support/workers/unique_job_with_filter_method.rb @@ -8,7 +8,7 @@ class UniqueJobWithFilterMethod lock: :while_executing, queue: :customqueue, retry: 1, - unique_args: :filtered_args + lock_args: :filtered_args def perform(*) # NO-OP diff --git a/spec/support/workers/unique_job_with_nil_unique_args.rb b/spec/support/workers/unique_job_with_nil_unique_args.rb index 2f92b5968..78c2e54a1 100644 --- a/spec/support/workers/unique_job_with_nil_unique_args.rb +++ b/spec/support/workers/unique_job_with_nil_unique_args.rb @@ -8,7 +8,7 @@ class UniqueJobWithNilUniqueArgs lock: :until_executed, queue: :customqueue, retry: true, - unique_args: :unique_args + lock_args: :unique_args def perform(args) [args] diff --git a/spec/support/workers/unique_job_with_no_unique_args_method.rb b/spec/support/workers/unique_job_with_no_unique_args_method.rb index 77109efef..309bf4398 100644 --- a/spec/support/workers/unique_job_with_no_unique_args_method.rb +++ b/spec/support/workers/unique_job_with_no_unique_args_method.rb @@ -8,7 +8,7 @@ class UniqueJobWithNoUniqueArgsMethod lock: :until_executed, queue: :customqueue, retry: true, - unique_args: :filtered_args + lock_args: :filtered_args def perform(one, two) [one, two] diff --git a/spec/support/workers/unique_job_without_unique_args_parameter.rb b/spec/support/workers/unique_job_without_unique_args_parameter.rb index ad670b263..e06513a34 100644 --- a/spec/support/workers/unique_job_without_unique_args_parameter.rb +++ b/spec/support/workers/unique_job_without_unique_args_parameter.rb @@ -8,7 +8,7 @@ class UniqueJobWithoutUniqueArgsParameter lock: :until_executed, queue: :customqueue, retry: true, - unique_args: :unique_args + lock_args: :unique_args def perform(optional = true) # NO-OP diff --git a/spec/workers/custom_queue_job_with_filter_method_spec.rb b/spec/workers/custom_queue_job_with_filter_method_spec.rb index 3e1deba9a..56e5df649 100644 --- a/spec/workers/custom_queue_job_with_filter_method_spec.rb +++ b/spec/workers/custom_queue_job_with_filter_method_spec.rb @@ -7,7 +7,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_executed, - "unique_args" => :args_filter, + "lock_args" => :args_filter, } end end diff --git a/spec/workers/custom_queue_job_with_filter_proc_spec.rb b/spec/workers/custom_queue_job_with_filter_proc_spec.rb index 9c2a53f07..ffadec59d 100644 --- a/spec/workers/custom_queue_job_with_filter_proc_spec.rb +++ b/spec/workers/custom_queue_job_with_filter_proc_spec.rb @@ -7,7 +7,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_expired, - "unique_args" => a_kind_of(Proc), + "lock_args" => a_kind_of(Proc), } end end diff --git a/spec/workers/my_unique_job_with_filter_method_spec.rb b/spec/workers/my_unique_job_with_filter_method_spec.rb index 5aab178c6..9d6d95f05 100644 --- a/spec/workers/my_unique_job_with_filter_method_spec.rb +++ b/spec/workers/my_unique_job_with_filter_method_spec.rb @@ -8,7 +8,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_executed, - "unique_args" => :filtered_args, + "lock_args" => :filtered_args, } end end diff --git a/spec/workers/my_unique_job_with_filter_proc_spec.rb b/spec/workers/my_unique_job_with_filter_proc_spec.rb index b556bf9b2..290c6d911 100644 --- a/spec/workers/my_unique_job_with_filter_proc_spec.rb +++ b/spec/workers/my_unique_job_with_filter_proc_spec.rb @@ -16,8 +16,8 @@ let(:args) { ["one", "type" => "unique", "id" => 2] } end - describe "unique_args" do - subject(:unique_args) { described_class.get_sidekiq_options["unique_args"].call(args) } + describe "lock_args" do + subject(:lock_args) { described_class.get_sidekiq_options["lock_args"].call(args) } let(:args) { ["one", "type" => "unique", "id" => 2] } diff --git a/spec/workers/simple_worker_spec.rb b/spec/workers/simple_worker_spec.rb index 60954f3e6..2019bbe4a 100644 --- a/spec/workers/simple_worker_spec.rb +++ b/spec/workers/simple_worker_spec.rb @@ -15,9 +15,9 @@ let(:args) { ["one", "type" => "unique", "id" => 2] } end - describe "unique_args" do + describe "lock_args" do subject do - described_class.get_sidekiq_options["unique_args"].call(args) + described_class.get_sidekiq_options["lock_args"].call(args) end let(:args) { ["unique", "type" => "unique", "id" => 2] } diff --git a/spec/workers/unique_job_with_nil_unique_args_spec.rb b/spec/workers/unique_job_with_nil_unique_args_spec.rb index c2cf06994..ff660bb29 100644 --- a/spec/workers/unique_job_with_nil_unique_args_spec.rb +++ b/spec/workers/unique_job_with_nil_unique_args_spec.rb @@ -8,7 +8,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_executed, - "unique_args" => :unique_args, + "lock_args" => :unique_args, } end end diff --git a/spec/workers/unique_job_with_no_unique_args_method_spec.rb b/spec/workers/unique_job_with_no_unique_args_method_spec.rb index 0f6a470bb..96aecbbb0 100644 --- a/spec/workers/unique_job_with_no_unique_args_method_spec.rb +++ b/spec/workers/unique_job_with_no_unique_args_method_spec.rb @@ -8,7 +8,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_executed, - "unique_args" => :filtered_args, + "lock_args" => :filtered_args, } end end diff --git a/spec/workers/unique_job_without_unique_args_parameter_spec.rb b/spec/workers/unique_job_without_unique_args_parameter_spec.rb index 690ef2136..badfd1f30 100644 --- a/spec/workers/unique_job_without_unique_args_parameter_spec.rb +++ b/spec/workers/unique_job_without_unique_args_parameter_spec.rb @@ -8,7 +8,7 @@ "queue" => :customqueue, "retry" => true, "lock" => :until_executed, - "unique_args" => :unique_args, + "lock_args" => :unique_args, } end end From 32cee97b45439fea3289acdfdb4fc7a957556a06 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 21 Mar 2020 14:28:00 +0100 Subject: [PATCH 2/5] Mandatory rubocop commit # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. --- spec/sidekiq_unique_jobs/lock_args_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/sidekiq_unique_jobs/lock_args_spec.rb b/spec/sidekiq_unique_jobs/lock_args_spec.rb index c52f75e0c..9ba8c0517 100644 --- a/spec/sidekiq_unique_jobs/lock_args_spec.rb +++ b/spec/sidekiq_unique_jobs/lock_args_spec.rb @@ -108,7 +108,7 @@ a_string_starting_with( "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ " received [1]", - ) + ), ) end @@ -122,7 +122,7 @@ a_string_starting_with( "UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments," \ " received []", - ) + ), ) end end @@ -138,8 +138,8 @@ SidekiqUniqueJobs::InvalidUniqueArguments, a_string_starting_with( 'UniqueJobWithoutUniqueArgsParameter#unique_args takes 0 arguments,' \ - ' received ["name", 2, {"whatever"=>nil, "type"=>"test"}]' \ - ) + ' received ["name", 2, {"whatever"=>nil, "type"=>"test"}]', \ + ), ) end end From cca31288a3d6acfa28b2531d7ac60fae81ba9ef1 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 21 Mar 2020 14:45:11 +0100 Subject: [PATCH 3/5] Adds missing tests for deprecations --- lib/sidekiq_unique_jobs/lock/validator.rb | 17 +++++++++++++ .../lock/validator_spec.rb | 24 ++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/sidekiq_unique_jobs/lock/validator.rb b/lib/sidekiq_unique_jobs/lock/validator.rb index 284ca978c..f1305e00d 100644 --- a/lib/sidekiq_unique_jobs/lock/validator.rb +++ b/lib/sidekiq_unique_jobs/lock/validator.rb @@ -8,6 +8,12 @@ class Lock # @author Mikael Henriksson # class Validator + DEPRECATED_KEYS = { + UNIQUE.to_sym => LOCK.to_sym, + UNIQUE_ARGS.to_sym => LOCK_ARGS.to_sym, + UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym + }.freeze + # # Shorthand for `new(options).validate` # @@ -30,6 +36,7 @@ def self.validate(options) # @param [Hash] options the sidekiq_options for the worker being validated # def initialize(options) + @options = options.transform_keys(&:to_sym) @lock_config = LockConfig.new(options) end @@ -40,6 +47,8 @@ def initialize(options) # @return [LockConfig] the lock configuration with errors if any # def validate + handle_deprecations + case lock_config.type when :while_executing validate_server @@ -53,6 +62,14 @@ def validate lock_config end + def handle_deprecations + DEPRECATED_KEYS.each do |old, new| + next unless @options.key?(old) + + lock_config.errors[old] = "is deprecated, use `#{new}: #{@options[old]}` instead." + end + end + # # Validates the client configuration # diff --git a/spec/sidekiq_unique_jobs/lock/validator_spec.rb b/spec/sidekiq_unique_jobs/lock/validator_spec.rb index c0d1036e6..f2cb2195f 100644 --- a/spec/sidekiq_unique_jobs/lock/validator_spec.rb +++ b/spec/sidekiq_unique_jobs/lock/validator_spec.rb @@ -15,11 +15,23 @@ it { expect(true).to eq(true) } - # describe ".validate" do - # subject(:validate) { described_class.validate({}) } - # end + describe "#validate" do + subject(:validate) { validator.validate } - # describe "#validate" do - # subject(:validate) { validator.validate } - # end + context "with deprecated sidekiq_options" do + let(:options) do + { + "unique" => "until_executed", + "unique_args" => "hokus", + "unique_prefix" => "pokus", + } + end + + it "writes a helpful message about the deprecated key" do + expect(validate.errors[:unique]).to eq('is deprecated, use `lock: until_executed` instead.') + expect(validate.errors[:unique_args]).to eq('is deprecated, use `lock_args: hokus` instead.') + expect(validate.errors[:unique_prefix]).to eq('is deprecated, use `lock_prefix: pokus` instead.') + end + end + end end From 0870fccda93e03e2865bb50ebc3e57fc41ecaf36 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 21 Mar 2020 14:45:31 +0100 Subject: [PATCH 4/5] Mandatory rubocop commit --- lib/sidekiq_unique_jobs/lock/validator.rb | 2 +- spec/sidekiq_unique_jobs/lock/validator_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sidekiq_unique_jobs/lock/validator.rb b/lib/sidekiq_unique_jobs/lock/validator.rb index f1305e00d..7eb1ab820 100644 --- a/lib/sidekiq_unique_jobs/lock/validator.rb +++ b/lib/sidekiq_unique_jobs/lock/validator.rb @@ -11,7 +11,7 @@ class Validator DEPRECATED_KEYS = { UNIQUE.to_sym => LOCK.to_sym, UNIQUE_ARGS.to_sym => LOCK_ARGS.to_sym, - UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym + UNIQUE_PREFIX.to_sym => LOCK_PREFIX.to_sym, }.freeze # diff --git a/spec/sidekiq_unique_jobs/lock/validator_spec.rb b/spec/sidekiq_unique_jobs/lock/validator_spec.rb index f2cb2195f..59afb6d20 100644 --- a/spec/sidekiq_unique_jobs/lock/validator_spec.rb +++ b/spec/sidekiq_unique_jobs/lock/validator_spec.rb @@ -28,9 +28,9 @@ end it "writes a helpful message about the deprecated key" do - expect(validate.errors[:unique]).to eq('is deprecated, use `lock: until_executed` instead.') - expect(validate.errors[:unique_args]).to eq('is deprecated, use `lock_args: hokus` instead.') - expect(validate.errors[:unique_prefix]).to eq('is deprecated, use `lock_prefix: pokus` instead.') + expect(validate.errors[:unique]).to eq("is deprecated, use `lock: until_executed` instead.") + expect(validate.errors[:unique_args]).to eq("is deprecated, use `lock_args: hokus` instead.") + expect(validate.errors[:unique_prefix]).to eq("is deprecated, use `lock_prefix: pokus` instead.") end end end From 14f6bc0ee37686ef4afba34ca5d989baf1c5cd51 Mon Sep 17 00:00:00 2001 From: mhenrixon Date: Sat, 21 Mar 2020 14:58:18 +0100 Subject: [PATCH 5/5] Mandatory reek commit --- lib/sidekiq_unique_jobs/lock/validator.rb | 3 +-- lib/sidekiq_unique_jobs/lock_args.rb | 8 ++++++-- lib/sidekiq_unique_jobs/lock_digest.rb | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/sidekiq_unique_jobs/lock/validator.rb b/lib/sidekiq_unique_jobs/lock/validator.rb index 7eb1ab820..e39b35e17 100644 --- a/lib/sidekiq_unique_jobs/lock/validator.rb +++ b/lib/sidekiq_unique_jobs/lock/validator.rb @@ -38,6 +38,7 @@ def self.validate(options) def initialize(options) @options = options.transform_keys(&:to_sym) @lock_config = LockConfig.new(options) + handle_deprecations end # @@ -47,8 +48,6 @@ def initialize(options) # @return [LockConfig] the lock configuration with errors if any # def validate - handle_deprecations - case lock_config.type when :while_executing validate_server diff --git a/lib/sidekiq_unique_jobs/lock_args.rb b/lib/sidekiq_unique_jobs/lock_args.rb index 69f3f1cc2..1b8ba6ddc 100644 --- a/lib/sidekiq_unique_jobs/lock_args.rb +++ b/lib/sidekiq_unique_jobs/lock_args.rb @@ -107,8 +107,12 @@ def lock_args_method # The global worker options defined in Sidekiq directly def default_lock_args_method - Sidekiq.default_worker_options.stringify_keys[LOCK_ARGS] || - Sidekiq.default_worker_options.stringify_keys[UNIQUE_ARGS] + default_worker_options[LOCK_ARGS] || + default_worker_options[UNIQUE_ARGS] + end + + def default_worker_options + @default_worker_options ||= Sidekiq.default_worker_options.stringify_keys end end end diff --git a/lib/sidekiq_unique_jobs/lock_digest.rb b/lib/sidekiq_unique_jobs/lock_digest.rb index ed1bd2ad7..7504a4435 100644 --- a/lib/sidekiq_unique_jobs/lock_digest.rb +++ b/lib/sidekiq_unique_jobs/lock_digest.rb @@ -36,8 +36,8 @@ def self.call(item) def initialize(item) @item = item @worker_class = item[CLASS] - @lock_args = item[LOCK_ARGS] || item[UNIQUE_ARGS] # TODO: Deprecate UNIQUE_ARGS - @lock_prefix = item[LOCK_PREFIX] || item[UNIQUE_PREFIX] # TODO: Deprecate UNIQUE_PREFIX + @lock_args = item.slice(LOCK_ARGS, UNIQUE_ARGS).values.first # TODO: Deprecate UNIQUE_ARGS + @lock_prefix = item.slice(LOCK_PREFIX, UNIQUE_PREFIX).values.first # TODO: Deprecate UNIQUE_PREFIX end # Memoized lock_digest