Module: ActiveJob::PerformLater::Macro

Defined in:
lib/active_job/perform_later/macro.rb

Overview

perform_later_job class macro, mixed into Module.

Instance Method Summary collapse

Instance Method Details

#perform_later_job(method_name = nil, on: nil) { ... } ⇒ Class

Defines a dedicated job class for method_name — or the class-wide PerformLaterJob fallback when no name is given — named after ActiveJob::PerformLater.job_const_name and inheriting from the nearest PerformLaterJob or ActiveJob::PerformLater.base_job.

Examples:

Dedicated job with options

class Report
  perform_later_job :generate, on: :instance do
    queue_as :reports
  end
end

Parameters:

  • method_name (Symbol, nil) (defaults to: nil) —

    method the job is dedicated to; nil declares the class-wide fallback job

  • on (Symbol, nil) (defaults to: nil) —

    restrict the job to :class or :instance calls of method_name

Yields:

  • optional block class_eval'ed inside the generated job (queue_as, retry_on, ...)

Returns:

  • (Class) —

    the generated job class

Raises:

  • (ArgumentError) —

    on an invalid scope, a scope without a method name, or an already-defined job constant