Skip to content

Notify When Sidekiq Job Defined Threshold or sidekiq.attempt_threshold is Reached #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGELOG](http://keepachangelog.com/) for how to update this file. This project
adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Issue a Notification from a Sidekiq job when either the `sidekiq.attempt_threshold` is reached OR if the job defined retry threshold is reached, whichever comes first.

## [4.1.0] - 2018-10-16
### Added
Expand Down
10 changes: 9 additions & 1 deletion lib/honeybadger/plugins/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ def call(worker, msg, queue)
::Sidekiq.configure_server do |sidekiq|
sidekiq.error_handlers << lambda {|ex, params|
job = params[:job] || params
return if job['retry'.freeze] && job['retry_count'.freeze].to_i < config[:'sidekiq.attempt_threshold'].to_i
retry_count = job['retry_count'.freeze].to_i
retry_opt = job['retry'.freeze]
max_retries = if retry_opt.is_a?(Integer)
[retry_opt - 1, config[:'sidekiq.attempt_threshold'].to_i].min
else
config[:'sidekiq.attempt_threshold'].to_i
end

return if retry_opt && retry_count < max_retries
opts = {parameters: params}
opts[:component] = job['wrapped'.freeze] || job['class'.freeze] if config[:'sidekiq.use_component']
Honeybadger.notify(ex, opts)
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/honeybadger/plugins/sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def self.configure_server
sidekiq_config.error_handlers[0].call(exception, job_context)
end
end

context "and the retry count meets the job set threshold" do
let(:job) { { 'retry_count' => 2, 'retry' => 2 } }

it "notifies Honeybadger" do
expect(Honeybadger).to receive(:notify).with(exception, { parameters: job_context, component: nil }).once
sidekiq_config.error_handlers[0].call(exception, job_context)
end
end
end
end
end
Expand Down