Class: ActiveJob::Base

Inherits:
Object show all
Includes:
Callbacks, Core, Exceptions, Instrumentation, Logging, QueueAdapter, QueueName, QueuePriority, Timezones, Translation, Enqueuing, Execution
Defined in:
activejob/lib/active_job/base.rb

Overview

Active Job Base

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 ActiveJob::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 ActiveJob::Core::ClassMethods#set

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

ProcessPhotoJob.perform_now(photo)

Exceptions

  • DeserializationError - Error class for deserialization errors.

  • SerializationError - Error class for serialization errors.

Constant Summary

Constants included from ActiveSupport::Callbacks

ActiveSupport::Callbacks::CALLBACK_FILTER_TYPES

Instance Attribute Summary

Attributes included from Core

#arguments, #enqueue_error, #enqueued_at, #exception_executions, #executions, #job_id, #locale, #priority, #provider_job_id, #queue_name, #scheduled_at, #serialized_arguments, #successfully_enqueued, #timezone

Method Summary

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from Logging

#perform_now

Methods included from Instrumentation

#perform_now

Methods included from Exceptions

#retry_job

Methods included from ActiveSupport::Callbacks

#run_callbacks

Methods included from QueuePriority

#priority

Methods included from QueueName

#queue_name

Methods included from Core

#deserialize, #initialize, #serialize, #set, #successfully_enqueued?