Reputation: 17599
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
Upvotes: 1
Views: 853
Reputation: 25142
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
Upvotes: 0
Reputation: 668
need's to add @retry_exceptions = [] before the retry_criteria_check de
Upvotes: 0
Reputation: 26384
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
Upvotes: 3