Module: Arj::Extensions::LastError
- Included in:
- Test::JobWithLastError
- Defined in:
- lib/arj/extensions/last_error.rb
Overview
Adds a last_error
attribute to a job class.
Example usage:
class AddLastErrorToJobs < ActiveRecord::Migration[7.1]
def change
add_column :jobs, :last_error, :text
end
end
class SampleJob < ActiveJob::Base
include Arj::Extensions::LastError
retry_on Exception
end
job = SampleJob.perform_later
job.perform_now # raises
job.last_error # contains the stacktrace of the previous error
Instance Attribute Summary collapse
-
#last_error ⇒ Object
A String representing the last error encountered during execution, if any.
Instance Method Summary collapse
-
#deserialize(job_data) ⇒ Object
Overridden to add support for deserializing the
last_error
attribute. -
#serialize ⇒ Object
Overridden to add support for serializing the
last_error
attribute. -
#set(options = {}) ⇒ Object
Overridden to add support for setting the
last_error
attribute.
Instance Attribute Details
#last_error ⇒ Object
A String representing the last error encountered during execution, if any.
25 26 27 |
# File 'lib/arj/extensions/last_error.rb', line 25 def last_error @last_error end |
Instance Method Details
#deserialize(job_data) ⇒ Object
Overridden to add support for deserializing the last_error
attribute.
53 54 55 |
# File 'lib/arj/extensions/last_error.rb', line 53 def deserialize(job_data) super.tap { @last_error = job_data['last_error'] } end |
#serialize ⇒ Object
Overridden to add support for serializing the last_error
attribute.
48 49 50 |
# File 'lib/arj/extensions/last_error.rb', line 48 def serialize super.merge('last_error' => @last_error) end |
#set(options = {}) ⇒ Object
Overridden to add support for setting the last_error
attribute.
41 42 43 44 45 |
# File 'lib/arj/extensions/last_error.rb', line 41 def set( = {}) super.tap do self.last_error = [:error] if [:error] end end |