Skip to content

Instantly share code, notes, and snippets.

@defkode
Created May 9, 2024 05:53
Show Gist options
  • Save defkode/3da234167d1a7bc18a46ff2e700c4d65 to your computer and use it in GitHub Desktop.
Save defkode/3da234167d1a7bc18a46ff2e700c4d65 to your computer and use it in GitHub Desktop.
SolidErrors - ActiveJob integration
# 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