Created
May 9, 2024 05:53
-
-
Save defkode/3da234167d1a7bc18a46ff2e700c4d65 to your computer and use it in GitHub Desktop.
SolidErrors - ActiveJob integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# catches errors from any ActiveJob::Base inherited classes like ApplicationJob | |
# and often overlooked ActionMailer::MailDeliveryJob which is wrapper for i.e: YourMailer.deliver_later | |
module SolidErrors::ActiveJob | |
extend ActiveSupport::Concern | |
included do | |
around_perform do |job, block| | |
Rails.error.record(StandardError, context: {job: job.class.name, job_id: job.job_id}) do | |
block.call | |
end | |
end | |
end | |
end | |
# config/initializers/solid_errors.rb | |
Rails.application.configure do | |
config.after_initialize do | |
ActiveJob::Base.include SolidErrors::ActiveJob | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment