Skip to content

Commit

Permalink
feat: track exceptions in :solid_queue (#526)
Browse files Browse the repository at this point in the history
And any other ActiveJob adapters that come along :)

Fixes #518
  • Loading branch information
stympy authored Mar 5, 2024
1 parent bbe162e commit 4e2d428
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 8 additions & 7 deletions lib/honeybadger/plugins/active_job.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
module Honeybadger
module Plugins
module ActiveJob

# Ignore inline and test adapters, as well as the adapters that we support with their own plugins
EXCLUDED_ADAPTERS = %i[inline test delayed_job faktory karafka resque shoryuken sidekiq sucker_punch].freeze

Plugin.register {
requirement { defined?(::Rails.application) && ::Rails.application }
requirement {
::Rails.application.config.respond_to?(:active_job) &&
::Rails.application.config.active_job[:queue_adapter] == :async
!EXCLUDED_ADAPTERS.include?(::Rails.application.config.active_job[:queue_adapter])
}

execution {
::ActiveJob::Base.class_eval do |base|
::ActiveJob::Base.class_eval do |base|
base.set_callback :perform, :around do |param, block|
Honeybadger.clear!
begin
block.call
rescue => error
Honeybadger.notify(error, parameters: { job_arguments: self.arguments })
Honeybadger.notify(error, parameters: {job_id: job_id, arguments: arguments})
raise error
end
end
end
end
}
}
end
end

end
7 changes: 3 additions & 4 deletions spec/integration/rails/async_queue_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative '../rails_helper'
require_relative "../rails_helper"

describe "Rails Async Queue Adapter Test", if: RAILS_PRESENT, type: :request do
include ActiveJob::TestHelper if RAILS_PRESENT
Expand All @@ -8,13 +8,12 @@
Honeybadger.flush do
perform_enqueued_jobs do
expect {
ErrorJob.perform_later({some: 'data'})
ErrorJob.perform_later({some: "data"})
}.to raise_error(StandardError)
end
end

expect(Honeybadger::Backend::Test.notifications[:notices].size).to eq(1)
expect(Honeybadger::Backend::Test.notifications[:notices][0].params[:job_arguments][0]).to eq({some: 'data'})
expect(Honeybadger::Backend::Test.notifications[:notices][0].params[:arguments][0]).to eq({some: "data"})
end

end

0 comments on commit 4e2d428

Please sign in to comment.