hakunin hakunin - 1 month ago 10
Ruby Question

Current Sidekiq job lost when deploying to Heroku

I have a Sidekiq job that runs for a while and when I deploy to Heroku and the job is running, it can't finish within in the few seconds.

That is fine, as the job is designed to be able to be re-run if needed.

The problem is that the job gets lost (instead of put back to redis and run again after deploy).

I found that it is advised to set

:timeout: 8
on heroku and I tried it, but it had no effect (also tried seeting to 5).

When there is an exception, I get errors reported, but I don't see any. So not sure what could be wrong.

Any tips on how to debug this?


The free version of Sidekiq will push unfinished jobs back to Redis after the timeout has passed, default of 8 seconds. Heroku gives a process 10 seconds to shut down. That means we have 2 seconds to get those jobs back to Redis or they will be lost. If your network is slow, if the Redis server is swapping, etc, that 2 sec deadline might not be met and the jobs lost.

You were on the right track: one answer is to lower the timeout so you have a better chance of meeting that deadline. But network or swapping delay can't be predicted: even 5 seconds might not be enough time.

Under normal healthy conditions, things should work as designed. Keep your machines healthy (uncongested network, plenty of RAM) and the basic fetch should work well. Sidekiq Pro's reliable fetch feature is a fundamental redesign of how Sidekiq fetches jobs and works around all of these issues by keeping jobs in Redis all the time so they can't be lost. But it comes with serious trade offs too: it's more complicated, slower and more Redis intensive than "basic" fetch.

In short, I don't know why you are losing jobs but make sure your instances and Redis server are healthy and the latency is low.