Class: Laters::InstanceMethodJob

Inherits:
Object
  • Object
show all
Defined in:
lib/laters/instance_method_job.rb

Overview

Job class that executes deferred instance methods with callbacks

This job is responsible for executing a method on an ActiveRecord object in the background. It runs all registered callbacks around the method execution.

Examples:

# This job is automatically used by the Laters::Concern
InstanceMethodJob.perform_later(user, "send_welcome_email", arg1, arg2)

Instance Method Summary collapse

Instance Method Details

#perform(object, method_name, *args, **kwargs) ⇒ Object

Executes the specified method on the given object

Parameters:

  • object (Object)

    The object to call the method on

  • method_name (String)

    The name of the method to call

  • args (Array)

    Arguments to pass to the method

  • kwargs (Hash)

    Keyword arguments to pass to the method

Returns:

  • (Object)

    The result of the method call

Raises:

  • (Exception)

    Any exception raised by the method



24
25
26
27
28
29
30
31
32
# File 'lib/laters/instance_method_job.rb', line 24

def perform(object, method_name, *args, **kwargs)
  if object.respond_to? :id
    Rails.logger.info "Calling deferred #{method_name} on #{object.class} ##{object.id}"
  else
    Rails.logger.info "Calling deferred #{object.class}##{method_name}"
  end

  object.run_callbacks(:laters) { object.send(method_name, *args, **kwargs) }
end