Class: RuboCop::Cop::Sidekiq::PerformInlineUsage

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

Overview

Checks for usage of perform_inline in production code.

perform_inline executes the job synchronously, bypassing the job queue. This can be useful in tests but should generally be avoided in production code.

Examples:

AllowedInTests: true (default)

# bad (in app/services/user_service.rb)
MyJob.perform_inline(user.id)

# good (in spec/jobs/my_job_spec.rb)
MyJob.perform_inline(user.id)

AllowedInTests: false

# bad (in any file)
MyJob.perform_inline(user.id)

Constant Summary collapse

MSG =
'Avoid using `perform_inline` in production code. ' \
'Use `perform_async` instead.'
RESTRICT_ON_SEND =
%i[perform_inline].freeze

Instance Method Summary collapse

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



29
30
31
32
33
# File 'lib/rubocop/cop/sidekiq/perform_inline_usage.rb', line 29

def on_send(node)
  return if allowed_in_tests? && in_test_file?

  add_offense(node)
end