Class: ActiveJob::Base
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
ActionMailer::MailDeliveryJob, ActiveRecord::DestroyAssociationAsyncJob
|
|
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
Enqueuing
- Attributes & Methods
Exceptions
- Attributes & Methods
Logging
- Attributes & Methods
- .log_arguments rw
- .log_arguments? ⇒ Boolean rw
-
.logger
(also: #logger)
rw
Accepts a logger conforming to the interface of Log4r or the default Ruby
Logger
class. - #logger rw
QueueAdapter
- Attributes & Methods
- ._queue_adapter rw
- ._queue_adapter_name rw
- #queue_adapter readonly
QueueName
- Attributes & Methods
QueuePriority
- Attributes & Methods
Class Method Summary
Instance Attribute Summary
Callbacks
- Included
Execution
- Included
Core
- Included
#arguments | Job arguments. |
#enqueue_error | Track any exceptions raised by the backend so callers can inspect the errors. |
#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 |
|
#serialized_arguments=, #successfully_enqueued?, | |
#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, |
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 25
class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false
._queue_adapter_name (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapter.rb', line 24
class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false
.after_discard_procs (rw)
[ GitHub ]# File 'activejob/lib/active_job/exceptions.rb', line 12
class_attribute :after_discard_procs, default: []
.after_discard_procs? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/exceptions.rb', line 12
class_attribute :after_discard_procs, default: []
.enqueue_after_transaction_commit (rw)
[ GitHub ]# File 'activejob/lib/active_job/enqueuing.rb', line 53
class_attribute :enqueue_after_transaction_commit, instance_accessor: false, instance_predicate: false, default: false
.log_arguments (rw)
[ GitHub ]# File 'activejob/lib/active_job/logging.rb', line 26
class_attribute :log_arguments, instance_accessor: false, default: true
.log_arguments? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/logging.rb', line 26
class_attribute :log_arguments, instance_accessor: false, default: true
.logger (rw) Also known as: #logger
Accepts a logger conforming to the interface of Log4r or the default Ruby Logger
class. You can retrieve this logger by calling logger
on either an Active Job job class or an Active Job job instance.
# File 'activejob/lib/active_job/logging.rb', line 15
cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
.priority (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_priority.rb', line 49
class_attribute :priority, instance_accessor: false, default: default_priority
.priority? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_priority.rb', line 49
class_attribute :priority, instance_accessor: false, default: default_priority
.queue_name (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 55
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 55
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 56
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_delimiter? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 56
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_prefix (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 57
class_attribute :queue_name_prefix
.queue_name_prefix? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 57
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
Instance Attribute Details
#after_discard_procs (rw)
[ GitHub ]# File 'activejob/lib/active_job/exceptions.rb', line 12
class_attribute :after_discard_procs, default: []
#after_discard_procs? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/exceptions.rb', line 12
class_attribute :after_discard_procs, default: []
#logger (rw)
[ GitHub ]# File 'activejob/lib/active_job/logging.rb', line 15
cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
#queue_adapter (readonly)
[ GitHub ]# File 'activejob/lib/active_job/queue_adapter.rb', line 27
delegate :queue_adapter, to: :class
#queue_name_prefix (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 57
class_attribute :queue_name_prefix
#queue_name_prefix? ⇒ Boolean
(rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 57
class_attribute :queue_name_prefix