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

4

3 に答える 3

3

カスタムの再試行基準を使用して、 resque-retry が再試行した回数を確認し、回数が多すぎる場合は別のことを行うことができます。このようなもの:

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
于 2012-09-05T02:08:22.703 に答える