-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track exceptions in :async activejob adapter (#503)
* WIP: Allow for exception tracking on async adapter. * Using perform_around callback to catch exceptions for ActiveJob * Restructure test for older rails versions * Make sure ActiveJob::TestHelper is only included when Rails is there * Test with around filter * Remove unnecessary test controller * call Honeybadger.clear! before executing job
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Honeybadger | ||
module Plugins | ||
module ActiveJob | ||
|
||
Plugin.register { | ||
requirement { defined?(::Rails.application) && ::Rails.application } | ||
requirement { | ||
::Rails.application.config.active_job[:queue_adapter] == :async | ||
} | ||
|
||
execution { | ||
::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 }) | ||
raise error | ||
end | ||
end | ||
end | ||
} | ||
} | ||
end | ||
end | ||
|
||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ErrorJob < ActiveJob::Base | ||
around_perform :around_for_testing | ||
|
||
def perform(opts={}) | ||
raise "exception raised in job" | ||
end | ||
|
||
def around_for_testing(*args) | ||
yield | ||
end | ||
end | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_relative '../rails_helper' | ||
|
||
describe "Rails Async Queue Adapter Test", if: RAILS_PRESENT, type: :request do | ||
include ActiveJob::TestHelper if RAILS_PRESENT | ||
load_rails_hooks(self) | ||
|
||
it "reports exceptions" do | ||
Honeybadger.flush do | ||
perform_enqueued_jobs do | ||
expect { | ||
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'}) | ||
end | ||
|
||
end |