Class: RuboCop::Cop::Sidekiq::RetrySpecified

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sidekiq/retry_specified.rb

Overview

Checks that Sidekiq jobs have explicit retry configuration.

Without explicit retry configuration, jobs use the default retry setting (25 retries). Being explicit about retry behavior makes the job's error handling clearer.

Examples:

# bad
class MyJob
  include Sidekiq::Job
end

# good
class MyJob
  include Sidekiq::Job
  sidekiq_options retry: 5
end

# good
class MyJob
  include Sidekiq::Job
  sidekiq_options retry: false
end

Constant Summary collapse

MSG =
'Specify retry configuration for this Sidekiq job using `sidekiq_options retry: ...`.'

Instance Method Summary collapse

Methods included from Sidekiq::Language

#active_job_class?, #perform_call?, #sidekiq_options_call?

Instance Method Details

#on_class(node) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rubocop/cop/sidekiq/retry_specified.rb', line 43

def on_class(node)
  return unless sidekiq_job_class?(node)
  return if retry_option?(node)

  include_node = find_sidekiq_include(node)
  add_offense(include_node) if include_node
end

#sidekiq_include?(node) ⇒ Object



34
35
36
# File 'lib/rubocop/cop/sidekiq/retry_specified.rb', line 34

def_node_matcher :sidekiq_include?, <<~PATTERN
  (send nil? :include (const (const {nil? cbase} :Sidekiq) {:Job :Worker}))
PATTERN

#sidekiq_options_with_retry?(node) ⇒ Object



39
40
41
# File 'lib/rubocop/cop/sidekiq/retry_specified.rb', line 39

def_node_matcher :sidekiq_options_with_retry?, <<~PATTERN
  (send nil? :sidekiq_options (hash <(pair (sym :retry) _) ...>))
PATTERN