class Base

Ruby on Rails 7.1.6

Since v4.2.9

Available in: v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

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.

Inherits from

Object

Includes

Used by

Subclasses (4)

Methods (inherited)

From ActiveJob::Core (5)
From ActiveJob::Enqueuing (1)
From ActiveJob::Exceptions (1)
From ActiveJob::Execution (2)
From ActiveJob::QueueName (1)
From ActiveJob::QueuePriority (1)
From Object (17)
From ActiveSupport::Callbacks (1)
From ActiveSupport::Concern (3)
From ActiveSupport::Rescuable (1)
From ActiveSupport::DescendantsTracker (4)

Type at least 2 characters to search.

↑↓ navigate · open · esc close