Sidekiq - Only handle error after x retries?
<p>I'm using sidekiq to process thousands of jobs per hour - all of which ping an external API (Google). One out of X thousand requests will return an unexpected (or empty) result. As far as I can tell, this is unavoidable when dealing with an external API.</p>

<p>Currently, when I encounter such response, I raise an Exception so that the retry logic will automatically take care of it on the next try. Something is only really wrong with the same job fails over and over many times. Exceptions are handled by Airbrake.</p>

<p>However my airbrake gets clogged up with these mini-outages that aren't really 'issues'. <strong>I'd like Airbrake to only be notified of these issues if the same job has failed X times already.</strong></p>

<p>Is it possible to either</p>

<ul>
<li>disable the automated airbrake integration so that I can use the sidekiq_retries_exhausted to report the error manually via Airbrake.notify</li>
<li>Rescue the error somehow so it doesn't notify Airbrake but keep retrying it?</li>
<li>Do this in a different way that I'm not thinking of?</li>
</ul>

<p>Here's my code outline</p>

<pre><code>class GoogleApiWorker
  include Sidekiq::Worker
   sidekiq_options queue: :critical, backtrace: 5

  def perform
    # Do stuff interacting with the google API
  rescue Exception =&gt; e
    if is_a_mini_google_outage? e
      # How do i make it so this harmless error DOES NOT get reported to Airbrake but still gets retried?
      raise e
    end
  end

  def is_a_mini_google_outage? e
    # check to see if this is a harmless outage
  end    
end
</code></pre>