Class: RuboCop::Cop::SidekiqPro::LargeArgumentInBatch

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sidekiq_pro/large_argument_in_batch.rb

Overview

Checks for large arguments passed to jobs within a batch.

When using batches, passing large arguments to jobs is especially problematic because it can exhaust Redis memory when many jobs are enqueued simultaneously.

Examples:

# bad
batch.jobs do
  items.each do |item|
    ProcessJob.perform_async(item.attributes)
  end
end

# good
batch.jobs do
  items.each do |item|
    ProcessJob.perform_async(item.id)
  end
end

Constant Summary collapse

MSG =
'Avoid passing large arguments to jobs within a batch. Pass IDs instead.'
DEFAULT_MAX_ARRAY_SIZE =
10
DEFAULT_MAX_HASH_SIZE =
10

Instance Method Summary collapse

Methods inherited from Base

#batch_description_set?, #batch_jobs_block?, #batch_new?, #batch_on_callback?

Methods included from Sidekiq::Language

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

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock



33
34
35
36
37
# File 'lib/rubocop/cop/sidekiq_pro/large_argument_in_batch.rb', line 33

def on_block(node)
  batch_jobs_block?(node) do |_receiver, body|
    check_body_for_large_arguments(body)
  end
end