123456789_123456789_123456789_123456789_123456789_

Class: ActiveJob::Base

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
ActionMailer::DeliveryJob
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 the queueing 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

Core - Attributes & Methods

Logging - Attributes & Methods

QueueName - Attributes & Methods

Class Method Summary

::ActiveSupport::DescendantsTracker - self

clear, descendants, direct_descendants,
store_inherited

This is the only method that is not thread safe, but is only ever called during the eager loading phase.

Instance Attribute Summary

Instance Method Summary

::ActiveSupport::Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

Execution - Included

#perform,
#perform_now

Performs the job immediately.

::ActiveSupport::Rescuable - Included

#handler_for_rescue,
#rescue_with_handler

Tries to rescue the exception by looking up and calling a registered handler.

Enqueuing - Included

#enqueue

Enqueues the job to be performed by the queue adapter.

#retry_job

Reschedules the job to be re-executed.

QueueName - Included

#queue_name

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

Core - Included

#initialize

Creates a new job instance.

#serialize

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

Class Attribute Details

.logger (rw) Also known as: #logger

[ GitHub ]

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

cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }

.queue_name (rw)

[ GitHub ]

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

class_attribute :queue_name, instance_accessor: false

.queue_name?Boolean (rw)

[ GitHub ]

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

class_attribute :queue_name, instance_accessor: false

.queue_name_delimiter (rw)

[ GitHub ]

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

class_attribute :queue_name_delimiter, instance_accessor: false

.queue_name_delimiter?Boolean (rw)

[ GitHub ]

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

class_attribute :queue_name_delimiter, instance_accessor: false

Instance Attribute Details

#arguments (rw)

Job arguments

[ GitHub ]

  
# File 'activejob/lib/active_job/core.rb', line 7

attr_accessor :arguments

#job_id (rw)

Job Identifier

[ GitHub ]

  
# File 'activejob/lib/active_job/core.rb', line 14

attr_accessor :job_id

#locale (rw)

I18n.locale to be used during the job.

[ GitHub ]

  
# File 'activejob/lib/active_job/core.rb', line 20

attr_accessor :locale

#logger (rw)

[ GitHub ]

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

cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }

#queue_name=(value) (writeonly)

Queue in which the job will reside.

[ GitHub ]

  
# File 'activejob/lib/active_job/core.rb', line 17

attr_writer :queue_name

#scheduled_at (rw)

Timestamp when the job should be performed

[ GitHub ]

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

attr_accessor :scheduled_at

#serialized_arguments=(value) (writeonly)

[ GitHub ]

  
# File 'activejob/lib/active_job/core.rb', line 8

attr_writer :serialized_arguments