- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (19)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (-6)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (38)
- 7.1.3.4 (0)
- What's this?
Active Job
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.