123456789_123456789_123456789_123456789_123456789_

Class: ActiveJob::Base

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Object
Defined in: activejob/lib/active_job/base.rb

Overview

Active Job objects can be configured to work with different backend queuing frameworks. To specify a queue adapter to use:

ActiveJob::Base.queue_adapter = :inline

A list of supported adapters can be found in QueueAdapters.

Active Job objects can be defined by creating a class that inherits from the Base class. The only necessary method to implement is the “perform” method.

To define an Active Job object:

class ProcessPhotoJob < ActiveJob::Base
  def perform(photo)
    photo.watermark!('Rails')
    photo.rotate!(90.degrees)
    photo.resize_to_fit!(300, 300)
    photo.upload!
  end
end

Records that are passed in are serialized/deserialized using Global ID. More information can be found in Arguments.

To enqueue a job to be performed as soon as the queuing system is free:

ProcessPhotoJob.perform_later(photo)

To enqueue a job to be processed at some point in the future:

ProcessPhotoJob.set(wait_until: Date.tomorrow.noon).perform_later(photo)

More information can be found in Core::ClassMethods#set

A job can also be processed immediately without sending to the queue:

ProcessPhotoJob.perform_now(photo)

Exceptions

Constant Summary

::ActiveSupport::Callbacks - Included

CALLBACK_FILTER_TYPES

Exceptions - Included

JITTER_DEFAULT

Exceptions - Attributes & Methods

Logging - Attributes & Methods

QueueAdapter - Attributes & Methods

QueueName - Attributes & Methods

QueuePriority - Attributes & Methods

Class Method Summary

Instance Attribute Summary

Logging - Included

Callbacks - Included

Execution - Included

Core - Included

#arguments

Job arguments.

#enqueue_error

Track any exceptions raised by the backend so callers can inspect the errors.

#enqueued_at

Track when a job was enqueued.

#exception_executions

::Hash that contains the number of times this job handled errors for each specific retry_on declaration.

#executions

Number of times this job has been executed (which increments on every retry, like after an exception).

#job_id

Job Identifier.

#locale

I18n.locale to be used during the job.

#priority=

Priority that the job will have (lower is more priority).

#provider_job_id

ID optionally provided by adapter.

#queue_name=

Queue in which the job will reside.

#scheduled_at

::Time when the job should be performed.

#serialized_arguments=, #successfully_enqueued?,
#timezone

Timezone to be used during the job.

#arguments_serialized?,
#successfully_enqueued=

Track whether the adapter received the job successfully.

Instance Method Summary

Logging - Included

Instrumentation - Included

Exceptions - Included

::ActiveSupport::Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

#halted_callback_hook

A hook invoked every time a before callback is halted.

Execution - Included

#perform,
#perform_now

Performs the job immediately.

#_perform_job

::ActiveSupport::Rescuable - Included

#rescue_with_handler

Delegates to the class method, but uses the instance as the subject for rescue_from handlers (method calls, instance_exec blocks).

#handler_for_rescue

Internal handler lookup.

Enqueuing - Included

#enqueue

Enqueues the job to be performed by the queue adapter.

#raw_enqueue

QueuePriority - Included

#priority

Returns the priority that the job will be created with.

QueueName - Included

#queue_name

Returns the name of the queue the job will be run on.

Core - Included

#deserialize

Attaches the stored job data to the current instance.

#initialize

Creates a new job instance.

#serialize

Returns a hash with the job data that can safely be passed to the queuing adapter.

#deserialize_arguments, #deserialize_arguments_if_needed, #serialize_arguments, #serialize_arguments_if_needed,
#set

Configures the job with the given options.

Class Attribute Details

._queue_adapter (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_adapter.rb', line 24

class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false

._queue_adapter_name (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_adapter.rb', line 23

class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false

.after_discard_procs (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/exceptions.rb', line 12

class_attribute :after_discard_procs, default: []

.after_discard_procs?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/exceptions.rb', line 12

class_attribute :after_discard_procs, default: []

.log_arguments (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/logging.rb', line 12

class_attribute :log_arguments, instance_accessor: false, default: true

.log_arguments?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/logging.rb', line 12

class_attribute :log_arguments, instance_accessor: false, default: true

.logger (rw) Also known as: #logger

[ GitHub ]

  
# File 'activejob/lib/active_job/logging.rb', line 11

cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

.priority (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_priority.rb', line 49

class_attribute :priority, instance_accessor: false, default: default_priority

.priority?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_priority.rb', line 49

class_attribute :priority, instance_accessor: false, default: default_priority

.queue_name (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 55

class_attribute :queue_name, instance_accessor: false, default: -> { self.class.default_queue_name }

.queue_name?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 55

class_attribute :queue_name, instance_accessor: false, default: -> { self.class.default_queue_name }

.queue_name_delimiter (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 56

class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"

.queue_name_delimiter?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 56

class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"

.queue_name_prefix (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 57

class_attribute :queue_name_prefix

.queue_name_prefix?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 57

class_attribute :queue_name_prefix

.retry_jitter (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/exceptions.rb', line 11

class_attribute :retry_jitter, instance_accessor: false, instance_predicate: false, default: 0.0

Instance Attribute Details

#after_discard_procs (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/exceptions.rb', line 12

class_attribute :after_discard_procs, default: []

#after_discard_procs?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/exceptions.rb', line 12

class_attribute :after_discard_procs, default: []

#logger (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/logging.rb', line 11

cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

#queue_adapter (readonly)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_adapter.rb', line 26

delegate :queue_adapter, to: :class

#queue_name_prefix (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 57

class_attribute :queue_name_prefix

#queue_name_prefix?Boolean (rw)

[ GitHub ]

  
# File 'activejob/lib/active_job/queue_name.rb', line 57

class_attribute :queue_name_prefix