Created
April 12, 2018 16:51
-
-
Save lucasmazza/31a0a3791f9a37da284344b6af3418cc to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
module Airbrake | |
module Sidekiq | |
# Internal: Airbrake filter that ignores exceptions from Sidekiq Jobs that | |
# will be retried. | |
class RetryableJobsFilter | |
def call(notice) | |
job = notice[:params][:job] | |
notice.ignore! if retryable?(job) | |
end | |
private | |
def retryable?(job) | |
return false if job.nil? || job['retry'].nil? | |
max_attempts = max_attempts_for(job) | |
job['retry_count'] < max_attempts | |
end | |
def max_attempts_for(job) | |
job['retry'].is_a?(Integer) ? job['retry'] : Sidekiq::JobRetry::DEFAULT_MAX_RETRY_ATTEMPTS | |
end | |
end | |
end | |
end | |
Airbrake.add_filter(Airbrake::Sidekiq::RetryableJobsFilter.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment