0

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.

basiszwo
  • 575
  • 3
  • 8
  • 1
    If you know that the ReadTimeout is just because the server is busy then this type of "workaround" is acceptable, but after 3 retries I would try to handle the error in some way. Here you are just throwing it away. But this is something your SysAdmin should know about. Server can't be unresponsive just like that. – Saša Zejnilović May 19 '17 at 11:26
  • Thank you for your answer. I do log relevant information anyway so I am not losing anything. I was just wondering if I missed sth in the sucker punch documentation / code that would have led to a better solution. Normally I use sidekiq for this but in this particular case I can't install additional software on the server. That's why sucker punch is pretty handy. – basiszwo May 19 '17 at 11:43

0 Answers0