Class: RuboCop::Cop::Salsify::DelayedJobSelfEnqueue

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/salsify/delayed_job_self_enqueue.rb

Overview

Detects ‘Delayed::Job.enqueue(self, …)`.

Re-enqueuing ‘self` serializes the entire object including memoized ActiveRecord instances. If any of those records are deleted before the job is next executed, deserialization will raise `Delayed::DeserializationError`. Create a fresh instance with only the primitive arguments instead.

Examples:


# bad
Delayed::Job.enqueue(self, run_at: 5.minutes.from_now)

# good
new_job = self.class.new(arg_one: arg_one, arg_two: arg_two)
Delayed::Job.enqueue(new_job, run_at: 5.minutes.from_now)

Constant Summary collapse

MSG =
'Do not pass `self` to `Delayed::Job.enqueue`. ' \
'Create a new job instance to avoid serializing memoized AR objects.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/salsify/delayed_job_self_enqueue.rb', line 34

def on_send(node)
  return unless enqueue_self?(node)

  add_offense(node, message: MSG)
end