basiszwo
basiszwo

Reputation: 620

Rails sucker punch - Is there a way to handle errors by retrying the action performed

In my application I am sending emails asynchronously with sucker punch gem.

Sometimes the mail server is very unresponsive and I get Net::ReadTimeout exceptions.

I am wondering if there is better way of handling errors than doing something like this

class DataJob
  include SuckerPunch::Job

  def perform(data)
    begin
      retries ||= 0

      puts data
    rescue Net::ReadTimeout
      sleep 10
      retry if (retries += 1) < 3
    end 
  end
end

In my code I integrated sucker punch with active job so basically I am just calling

Mailer.some_notification(my_object).deliver_later

which would require some refactoring. This is not a problem at all. I just wanted to include this bit of information.

Upvotes: 0

Views: 436

Answers (0)

Related Questions