Class: RuboCop::Cop::Sidekiq::MissingTimeout

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

Overview

Checks for network calls without explicit timeouts in Sidekiq jobs.

Examples:

# bad
Net::HTTP.get(URI(url))

# good
http.open_timeout = 5
http.read_timeout = 10

Constant Summary collapse

MSG =
'Configure explicit timeouts for network calls in Sidekiq jobs.'
HTTP_METHODS =
i[get post put delete].freeze
TIMEOUT_METHODS =
i[timeout= open_timeout= read_timeout=].freeze

Instance Method Summary collapse

Methods included from Sidekiq::Language

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

Instance Method Details

#on_def(node) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/cop/sidekiq/missing_timeout.rb', line 22

def on_def(node)
  return unless node.method?(:perform)
  return unless in_sidekiq_job?(node)
  return if timeout_configured?(node)

  node.each_descendant(:send) do |send|
    next unless network_call?(send)

    add_offense(send)
  end
end