Skip to content

Commit

Permalink
Add active_job.attempt_threshold configuration option (#535)
Browse files Browse the repository at this point in the history
Fixes #534
  • Loading branch information
stympy authored Mar 23, 2024
1 parent 22a9e73 commit 2237541
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/honeybadger/config/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ class Boolean; end
default: false,
type: Boolean
},
:'active_job.attempt_threshold' => {
description: 'The number of attempts before notifications will be sent.',
default: 0,
type: Integer
},
:'delayed_job.attempt_threshold' => {
description: 'The number of attempts before notifications will be sent.',
default: 0,
Expand Down
6 changes: 5 additions & 1 deletion lib/honeybadger/plugins/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def perform_around(job, block)
context = context(job)
block.call
rescue StandardError => e
Honeybadger.notify(e, context: context, parameters: { arguments: job.arguments })
Honeybadger.notify(
e,
context: context,
parameters: { arguments: job.arguments }
) if job.executions >= Honeybadger.config[:'active_job.attempt_threshold'].to_i
raise e
end

Expand Down
16 changes: 16 additions & 0 deletions spec/integration/rails/active_job_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@
scheduled_at: anything
)
end

it 'does not report exceptions if the attempt threshold is not reached', focus: true do
Honeybadger.config[:'active_job.attempt_threshold'] = 2

Honeybadger.flush do
perform_enqueued_jobs do
expect do
ErrorJob.perform_later({ some: 'data' })
end.to raise_error(StandardError)
end
end

expect(Honeybadger::Backend::Test.notifications[:notices].size).to eq(0)

Honeybadger.config[:'active_job.attempt_threshold'] = 0
end
end

0 comments on commit 2237541

Please sign in to comment.