1

I have a resque job that is supposed to call a third-party API. I want this perform method to retry at least 3 times. If it still does not go through on the third try, I want it to send an e-mail to me saying that something went wrong and the API could not be called.

Is there a way to do this using resque-retry

denniss
  • 17,229
  • 26
  • 92
  • 141

3 Answers3

3

You could use custom retry criteria to check how many times resque-retry has retried for you and do something different if the number is too large. Something like this:

class APIWorker
  extend Resque::Plugins::Retry
  @queue = :api_worker_queue

  retry_criteria_check do |exception, *args|
    if retry_attempt > 3
      send_email

      false # don't retry anymore
    else
      true # continue retrying
    end
  end

  def self.perform(job_id)
    do_api_stuff
  end
end
Gordon Wilson
  • 26,244
  • 11
  • 57
  • 60
0

need's to add @retry_exceptions = [] before the retry_criteria_check de

ilan weissberg
  • 658
  • 1
  • 7
  • 13
0

If you're using ActiveJob with Resque you can use ActiveJob's retry_on feature.

class RemoteServiceJob < ActiveJob::Base
  retry_on(SomeError) do |job, error|
    # your custom logic
  end
end
thisismydesign
  • 21,553
  • 9
  • 123
  • 126