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?
Asked
Active
Viewed 1,705 times
2 Answers
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
-
1You might have to rescue `Timeout::Error`. – nishu Aug 18 '14 at 04:18
-
1It depends on whether you want the jobs to fail with `Timeout::Error` errors and whether you need to clean anything up before exiting. – infused Aug 18 '14 at 04:20
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