Class: ActiveJob::Base
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| 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
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
Logging - Included
Callbacks - Included
Execution - Included
QueuePriority - Included
QueueName - 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. |
| #arguments_serialized?, | |
| #successfully_enqueued= | Track whether the adapter received the job successfully. |
Instance Method Summary
ExecutionState - Included
Logging - Included
Instrumentation - Included
Exceptions - Included
| #retry_job | Reschedules the job to be re-executed. |
| #determine_delay, #determine_jitter_for_delay, #executions_for, #run_after_discard_procs | |
::ActiveSupport::Callbacks - Included
| #run_callbacks | Runs the callbacks for the given event. |
| #halted_callback_hook | A hook invoked every time a before callback is halted. |
Execution - Included
| #perform, | |
| #perform_now | Performs the job immediately. |
| #_perform_job | |
::ActiveSupport::Rescuable - Included
| #rescue_with_handler | Delegates to the class method, but uses the instance as the subject for rescue_from handlers (method calls, |
| #handler_for_rescue | Internal handler lookup. |
Enqueuing - Included
| #enqueue | Enqueues the job to be performed by the queue adapter. |
| #_raw_enqueue, #raw_enqueue | |
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. |
| #deserialize_arguments, #deserialize_arguments_if_needed, #deserialize_time, #serialize_arguments, #serialize_arguments_if_needed, | |
| #set | Configures the job with the given options. |
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 23
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 33
class_attribute :log_arguments, instance_accessor: false, default: true
.log_arguments? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/logging.rb', line 33
class_attribute :log_arguments, instance_accessor: false, default: true
.priority (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_priority.rb', line 51
class_attribute :priority, instance_accessor: false, default: ActiveSupport::Ractors.shareable_proc { self.class.default_priority }
.priority? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_priority.rb', line 51
class_attribute :priority, instance_accessor: false, default: ActiveSupport::Ractors.shareable_proc { self.class.default_priority }
.queue_name (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 62
class_attribute :queue_name, instance_accessor: false, default: ActiveSupport::Ractors.shareable_proc { self.class.default_queue_name }
.queue_name? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 62
class_attribute :queue_name, instance_accessor: false, default: ActiveSupport::Ractors.shareable_proc { self.class.default_queue_name }
.queue_name_delimiter (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 63
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_delimiter? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 63
class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
.queue_name_prefix (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 64
class_attribute :queue_name_prefix
.queue_name_prefix? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 64
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: []
#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 64
class_attribute :queue_name_prefix
#queue_name_prefix? ⇒ Boolean (rw)
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 64
class_attribute :queue_name_prefix