Class: RuboCop::Cop::SidekiqEnt::UniqueUntilMismatch

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sidekiq_ent/unique_until_mismatch.rb

Overview

Checks that unique_until option has an appropriate value.

Using unique_until: :start may cause unexpected behavior as the lock is released when the job starts, allowing concurrent execution of identical jobs.

Examples:

# bad - lock released on start
class MyJob
  include Sidekiq::Job
  sidekiq_options unique_for: 600, unique_until: :start
end

# good - default behavior (success)
class MyJob
  include Sidekiq::Job
  sidekiq_options unique_for: 600
end

# good - explicit success
class MyJob
  include Sidekiq::Job
  sidekiq_options unique_for: 600, unique_until: :success
end

Constant Summary collapse

MSG =
'Avoid `unique_until: :%<value>s`. ' \
'Prefer `unique_until: :success` (default) to prevent concurrent execution.'
ALLOWED_VALUES =
%i[success].freeze

Instance Method Summary collapse

Methods inherited from Base

#limiter_creation?, #unique_for_option?, #unique_until_option?

Methods included from Sidekiq::Language

#active_job_class?, #perform_call?, #sidekiq_include?, #sidekiq_options_call?

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



42
43
44
45
46
47
48
# File 'lib/rubocop/cop/sidekiq_ent/unique_until_mismatch.rb', line 42

def on_send(node)
  unique_until_value(node) do |value|
    return if allowed_values.include?(value)

    add_offense(node, message: format(MSG, value: value))
  end
end

#unique_until_value(node) ⇒ Object



38
39
40
# File 'lib/rubocop/cop/sidekiq_ent/unique_until_mismatch.rb', line 38

def_node_matcher :unique_until_value, <<~PATTERN
  (send nil? :sidekiq_options (hash <(pair (sym :unique_until) (sym $_)) ...>))
PATTERN