I have a background worker that is a queue worker for a Bull JS node queue.
The problem is that if it auto deploys, there is a period of time when there are two instances of the workers running (each job takes around 45 seconds or so).
What I’d like to do is on deploy to ensure that when the new instance of the background service is running that the old instance is killed. It’s okay if the old instance gets killed while processing a job (it’ll just retry on the new instance). I could suspend the web service each time and then redeploy, but I was wondering if there was a more elegant way of doing this.
When a new version of your app is deployed, we keep the existing version up and continue to run it. Once the new version is live, we terminate the old version by sending your app a SIGTERM signal. Most web servers automatically intercept SIGTERM and shut down gracefully. There is a grace period of 30 seconds to shut everything down. If your app is still up after 30 seconds, it is shut down via a SIGKILL signal. Unfortunately, right now, there isn’t a way to configure this on an individual application level. One possible workaround you can do is to add a disk to your background worker. Services with disks are prevented from using zero-downtime deploys.