Skip to content Skip to sidebar Skip to footer

Capture Heroku Sigterm In Celery Workers To Shutdown Worker Gracefully

I've done a ton of research on this, and I'm surprised I haven't found a good answer to this yet anywhere. I'm running a large application on Heroku, and I have certain celery task

Solution 1:

Starting in version >= 4, Celery comes with a special feature, just for Heroku, that supports this functionality out of the box:

$ REMAP_SIGTERM=SIGQUIT celery -A proj worker -l info

source: https://devcenter.heroku.com/articles/celery-heroku#using-remap_sigterm

Solution 2:

celery was unfortunately not designed to do clean shutdown. EVER. I mean it. celery workers respond to SIGTERM but if a task is incomplete, the worker processes will wait to finish the task and only then exit. In which case, you can send it SIGKILL if the workers don't shut down in a reasonable time but there will be a loss of information in this case i.e. you may not know which jobs remained incomplete.

Solution 3:

You can use acks_late or task_acks_late.

Tasks will be acknowledged from queue after task finished execution and not just before. So task will respawn if worker shutdown gracefully.

Post a Comment for "Capture Heroku Sigterm In Celery Workers To Shutdown Worker Gracefully"