5

I have jobs does it take more than 2h to finish. I want to put a time to limit how long it will take it. How do i can do?

tenaz3.comp
  • 367
  • 6
  • 17

2 Answers2

7

Wrap the logic with Timeout::timeout and disable retries if you don't want the job to be retried after a timeout.

class RunsTooLongWorker
  include Sidekiq::Worker

  sidekiq_options :retry => false

  def perform(*args)
    Timeout::timeout(2.hours) do
      # do possibly long running task
    end
  end
end
infused
  • 24,000
  • 13
  • 68
  • 78
0

Use Ruby's timeout library to raise an error if it takes too long.

Mike Perham
  • 21,300
  • 6
  • 59
  • 61
  • https://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/ probably not a good idea given this post – rgalindo33 Jun 01 '20 at 12:06
  • Why do you think I would recommend it in one thing and recommend against it in another? Because "it depends" is really the answer and we don't have enough context to judge either way. – Mike Perham Jun 02 '20 at 18:51