Class: RuboCop::Cop::SidekiqEnt::UniqueJobWithoutTTL

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

Overview

Checks that unique jobs specify the unique_for option.

Sidekiq Enterprise unique jobs require a TTL (unique_for) to be specified. Without it, uniqueness locks may persist indefinitely if jobs fail.

Examples:

# bad - unique_until without unique_for
class MyJob
  include Sidekiq::Job
  sidekiq_options unique_until: :start
end

# good - both unique_for and unique_until specified
class MyJob
  include Sidekiq::Job
  sidekiq_options unique_for: 1.hour, unique_until: :start
end

Constant Summary collapse

MSG =
'Specify `unique_for` option when using unique jobs.'

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



32
33
34
35
36
37
38
39
# File 'lib/rubocop/cop/sidekiq_ent/unique_job_without_ttl.rb', line 32

def on_send(node)
  sidekiq_options_with_unique?(node) do |pairs|
    has_unique_until = pairs.any? { |pair| option_key?(pair, :unique_until) }
    has_unique_for = pairs.any? { |pair| option_key?(pair, :unique_for) }

    add_offense(node) if has_unique_until && !has_unique_for
  end
end

#sidekiq_options_with_unique?(node) ⇒ Object



28
29
30
# File 'lib/rubocop/cop/sidekiq_ent/unique_job_without_ttl.rb', line 28

def_node_matcher :sidekiq_options_with_unique?, <<~PATTERN
  (send nil? :sidekiq_options (hash $...))
PATTERN