Heroku delayed_job workers killed during deployment
On Heroku, I use delayed_job to start asynchronous tasks. Everything is fine until I find the git push heroku master and then Heroku environment kills all worker threads that are in the process.
The problem here is that these jobs are never reinstalled as the delayed_job table in my db shows they are still locked and running, even though the workers who used to serve them were long dead.
How can this situation be prevented? I would like Heroku to wait for all slowed jobs to complete before completing or fail before shutting down, or at least to terminate them and allow a new worker to be assigned after the server returns after a reboot with applied changes as per my update.
source to share
It looks like you can set up DJ to handle SIGTERM and mark unfinished jobs as unsuccessful (so they restart again):
Use this parameter to throw an exception on TERM signals by adding this to your initializer:
Delayed::Worker.raise_signal_exceptions = :term
More info in this answer: fooobar.com/questions/437844 / ...
source to share