Safe shut down for Celery

Hi all,

I’m currently running Celery as a background worker on Render. Before each deploy, I want celery to be cleanly shut down so any running tasks can complete + scheduled tasks can be returned to the broker. Current behavior seems to be that the process is simply killed immediately on each deploy, which is leading to lost tasks. How can I set up “clean” shutdowns with auto-deploy?

Hi @ashwinsr, we do send a SIGTERM to allow existing tasks to complete before stopping, however the issue is likely due to the fact that there is only a 30 second grace period for the workers to stop.

We do have one-off jobs that are in the works (early access now). They are intended to run to completion with no time limit, and might be a better fit for your use case.

Hi there,

Just to add here - the behaviour you’re looking for is Celery to cleanly handle a SIGTERM. I think you can achieve this with an environment variable REMAP_SIGTERM=SIGQUIT but I’d encourage you to investigate this yourself.