123456789_123456789_123456789_123456789_123456789_

Class: ActiveJob::Base

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

QueueAdapter - Attributes & Methods

QueueName - Attributes & Methods

QueuePriority - 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

Exceptions - Included

#retry_job

Reschedules the job to be re-executed.

::ActiveSupport::Callbacks - Included

#run_callbacks

Runs the callbacks for the given event.

Execution - Included

#perform,
#perform_now

Performs the job immediately.

::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).

Enqueuing - Included

#enqueue

Enqueues the job to be performed by the queue adapter.

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 queueing adapter.

Class Attribute Details

._queue_adapter (rw)

[ GitHub ]

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

class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false

._queue_adapter_name (rw)

[ GitHub ]

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

class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false

.logger (rw) Also known as: #logger

[ GitHub ]

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

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

.priority (rw)

[ GitHub ]

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

class_attribute :priority, instance_accessor: false, default: default_priority

.priority?Boolean (rw)

[ GitHub ]

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

class_attribute :priority, instance_accessor: false, default: default_priority

.queue_name (rw)

[ GitHub ]

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

class_attribute :queue_name, instance_accessor: false, default: default_queue_name

.queue_name?Boolean (rw)

[ GitHub ]

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

class_attribute :queue_name, instance_accessor: false, default: default_queue_name

.queue_name_delimiter (rw)

[ GitHub ]

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

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

.queue_name_delimiter?Boolean (rw)

[ GitHub ]

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

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

Instance Attribute Details

#arguments (rw)

Job arguments

[ GitHub ]

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

attr_accessor :arguments

#executions (rw)

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

[ GitHub ]

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

attr_accessor :executions

#job_id (rw)

Job Identifier

[ GitHub ]

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

attr_accessor :job_id

#locale (rw)

I18n.locale to be used during the job.

[ GitHub ]

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

attr_accessor :locale

#logger (rw)

[ GitHub ]

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

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

#priority=(value) (writeonly)

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

[ GitHub ]

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

attr_writer :priority

#provider_job_id (rw)

ID optionally provided by adapter

[ GitHub ]

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

attr_accessor :provider_job_id

#queue_name=(value) (writeonly)

Queue in which the job will reside.

[ GitHub ]

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

attr_writer :queue_name

#scheduled_at (rw)

Timestamp when the job should be performed

[ GitHub ]

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

attr_accessor :scheduled_at

#serialized_arguments=(value) (writeonly)

[ GitHub ]

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

attr_writer :serialized_arguments