title: Retry Sidekiq worker from within worker
body: <p>In my app I am trying to perform two worker tasks sequentially.
  First, a PDF is being created with Wicked pdf and then, once the PDF is created, to send an email to two different recipients with the PDF attached. </p>
  
  <p>This is what is called in the controller : </p>
  
  <pre><code>PdfWorker.perform_async(@d.id)
  MailingWorker.perform_in(1.minutes, @d.id,@d.class.name.to_s)
  </code></pre>
  
  <p>First worker creates the PDF and second worker sends email. </p>
  
  <p>Here is second worker : </p>
  
  <pre><code>class MailingWorker
    include Sidekiq::Worker
    sidekiq_options retry: false    
    def perform(d_id,model)
  
      @d = eval(model).find(d_id)
      @model = model
      if @d.pdf.present?
        ProfessionnelMailer.notification_d(@d).deliver
        ClientMailer.notification_d(@d).deliver
      else
        MailingWorker.perform_in(1.minutes, @d.id, @model.to_s)
      end
    end
  end
  </code></pre>
  
  <p>The if statement checks if the PDF has been created. If true two mails are sent, otherwise, the same worker is called again one minute later, just to let the Heroku server extra time to process the PDF creation in case it takes more time or a long queue. </p>
  
  <p>Though if the PDF has definitely failed to be processed, the above ends up in an infinite loop. </p>
  
  <p>Is there a way to fix this ?</p>
  
  <p>One option I see is calling the second worker inside the PDF creation worker though I don't really want to nest workers too deep. It makes my controller more clear to have them separate, I can see the sequence of actions. But any advice welcome.</p>
  
  <p>Another option is to use <code>sidekiq_options retry: 5</code> and request a retry of the controller that could be counted towards the full total of 5 retries, instead of retrying the worker with <code>else MailingWorker.perform_in(1.minutes, @d.id, @model.to_s)</code> but I don't know how to do this. As per this thread <a href="https://github.com/mperham/sidekiq/issues/769" rel="nofollow noreferrer">https://github.com/mperham/sidekiq/issues/769</a> it would be to raise an exception but I am not sure how to do this ... (also I am not sure how long the retry will wait before being processed with the exception method, with the solution above I can control the time frame..)</p>