Skip to content

Instantly share code, notes, and snippets.

@lucasmazza
Created April 12, 2018 16:51
Show Gist options
  • Save lucasmazza/31a0a3791f9a37da284344b6af3418cc to your computer and use it in GitHub Desktop.
Save lucasmazza/31a0a3791f9a37da284344b6af3418cc to your computer and use it in GitHub Desktop.
# 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