title: Rails sucker punch - Is there a way to handle errors by retrying the action performed
body: <p>In my application I am sending emails asynchronously with <a href="https://github.com/brandonhilkert/sucker_punch" rel="nofollow noreferrer">sucker punch gem</a>.</p>
  
  <p>Sometimes the mail server is very unresponsive and I get <code>Net::ReadTimeout</code> exceptions.</p>
  
  <p>I am wondering if there is better way of handling errors than doing something like this</p>
  
  <pre><code>class DataJob
    include SuckerPunch::Job
  
    def perform(data)
      begin
        retries ||= 0
  
        puts data
      rescue Net::ReadTimeout
        sleep 10
        retry if (retries += 1) &lt; 3
      end 
    end
  end
  </code></pre>
  
  <p>In my code I integrated sucker punch with active job so basically I am just calling </p>
  
  <pre><code>Mailer.some_notification(my_object).deliver_later
  </code></pre>
  
  <p>which would require some refactoring. This is not a problem at all. I just wanted to include this bit of information.</p>