How to kill a job in Sidekiq took a long time to finish

I have jobs; it takes more than 2 hours to complete. I want to put in time to limit how long it takes. How can i do this?

+4
source share
2 answers

Wrap the logic with Timeout::timeoutand turn off retries if you do not want the job to repeat 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
+6
source

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

0
source

All Articles