Class: ActiveJob::Base
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionMailer::DeliveryJob, ActionMailer::MailDeliveryJob, ActiveRecord::DestroyAssociationAsyncJob, 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 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 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
Callbacks
- Attributes & Methods
Exceptions
- Attributes & Methods
Logging
- Attributes & Methods
- .log_arguments rw
- .log_arguments? ⇒ Boolean rw
- .logger (also: #logger) rw
- #logger rw
QueueAdapter
- Attributes & Methods
- ._queue_adapter rw
- ._queue_adapter_name rw
- #queue_adapter readonly
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. |
subclasses |
Instance Attribute Summary
Callbacks
- Included
Execution
- Included
Core
- Included
#arguments | Job arguments. |
#enqueued_at | Track when a job was enqueued. |
#exception_executions |
|
#executions | Number of times this job has been executed (which increments on every retry, like after an exception). |
#job_id | Job Identifier. |
#locale |
|
#priority= | Priority that the job will have (lower is more priority). |
#provider_job_id | ID optionally provided by adapter. |
#queue_name= | Queue in which the job will reside. |
#scheduled_at | Timestamp when the job should be performed. |
#serialized_arguments=, | |
#timezone | Timezone to be used during the job. |
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 queuing 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
.log_arguments (rw)
[ GitHub ]# File 'activejob/lib/active_job/logging.rb', line 12
class_attribute :log_arguments, instance_accessor: false, default: true
.log_arguments? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/logging.rb', line 12
class_attribute :log_arguments, instance_accessor: false, default: true
.logger (rw) Also known as: #logger
[ GitHub ]# File 'activejob/lib/active_job/logging.rb', line 11
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 56
class_attribute :queue_name, instance_accessor: false, default: -> { self.class.default_queue_name }
.queue_name? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 56
class_attribute :queue_name, instance_accessor: false, default: -> { self.class.default_queue_name }
.queue_name_delimiter (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 57
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_delimiter? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 57
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_prefix (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 58
class_attribute :queue_name_prefix
.queue_name_prefix? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 58
class_attribute :queue_name_prefix
.retry_jitter (rw)
[ GitHub ]# File 'activejob/lib/active_job/exceptions.rb', line 11
class_attribute :retry_jitter, instance_accessor: false, instance_predicate: false, default: 0.0
.return_false_on_aborted_enqueue (rw)
[ GitHub ]# File 'activejob/lib/active_job/callbacks.rb', line 32
class_attribute :return_false_on_aborted_enqueue, instance_accessor: false, instance_predicate: false, default: false
.skip_after_callbacks_if_terminated (rw)
[ GitHub ]# File 'activejob/lib/active_job/callbacks.rb', line 34
cattr_accessor :skip_after_callbacks_if_terminated, instance_accessor: false, default: false
Instance Attribute Details
#logger (rw)
[ GitHub ]# File 'activejob/lib/active_job/logging.rb', line 11
cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
#queue_adapter (readonly)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapter.rb', line 15
delegate :queue_adapter, to: :class
#queue_name_prefix (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 58
class_attribute :queue_name_prefix
#queue_name_prefix? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 58
class_attribute :queue_name_prefix