Module: ActiveJob::Core
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveSupport::Concern
|
|
Defined in: | activejob/lib/active_job/core.rb |
Overview
Provides general behavior that will be included into every Active Job object that inherits from Base
.
Class Method Summary
::ActiveSupport::Concern
- Extended
Instance Method Summary
-
#deserialize(job_data)
Attaches the stored job data to the current instance.
-
#initialize(*arguments)
Creates a new job instance.
-
#serialize
Returns a hash with the job data that can safely be passed to the queueing adapter.
DSL Calls
included
[ GitHub ]9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# File 'activejob/lib/active_job/core.rb', line 9
included do # Job arguments attr_accessor :arguments attr_writer :serialized_arguments # Timestamp when the job should be performed attr_accessor :scheduled_at # Job Identifier attr_accessor :job_id # Queue in which the job will reside. attr_writer :queue_name # Priority that the job will have (lower is more priority). attr_writer :priority # ID optionally provided by adapter attr_accessor :provider_job_id # Number of times this job has been executed (which increments on every retry, like after an exception). attr_accessor :executions # I18n.locale to be used during the job. attr_accessor :locale end
Instance Method Details
#deserialize(job_data)
Attaches the stored job data to the current instance. Receives a hash returned from #serialize
Examples
class DeliverWebhookJob < ActiveJob::Base
attr_writer :attempt_number
def attempt_number
@attempt_number ||= 0
end
def serialize
super.merge('attempt_number' => attempt_number + 1)
end
def deserialize(job_data)
super
self.attempt_number = job_data['attempt_number']
end
rescue_from(Timeout::Error) do |exception|
raise exception if attempt_number > 5
retry_job(wait: 10)
end
end
# File 'activejob/lib/active_job/core.rb', line 120
def deserialize(job_data) self.job_id = job_data["job_id"] self.provider_job_id = job_data["provider_job_id"] self.queue_name = job_data["queue_name"] self.priority = job_data["priority"] self.serialized_arguments = job_data["arguments"] self.executions = job_data["executions"] self.locale = job_data["locale"] || I18n.locale.to_s end
#initialize(*arguments)
Creates a new job instance. Takes the arguments that will be passed to the perform method.
# File 'activejob/lib/active_job/core.rb', line 71
def initialize(*arguments) @arguments = arguments @job_id = SecureRandom.uuid @queue_name = self.class.queue_name @priority = self.class.priority @executions = 0 end
#serialize
Returns a hash with the job data that can safely be passed to the queueing adapter.
# File 'activejob/lib/active_job/core.rb', line 81
def serialize { "job_class" => self.class.name, "job_id" => job_id, "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority, "arguments" => serialize_arguments_if_needed(arguments), "executions" => executions, "locale" => I18n.locale.to_s } end