level12 / keg-app-cookiecutter

0 stars 0 forks source link

revisit best way to manage celery from uwsgi #48

Closed rsyring closed 6 years ago

rsyring commented 6 years ago

uwsgi docs give this example for Celery:

[uwsgi]
master = true
socket = :3031
smart-attach-daemon = /tmp/celery.pid celery -A tasks worker --pidfile=/tmp/celery.pid

See: http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html

nZac commented 6 years ago

This is correct if we want to manage the celery process our self. The uWSGI process will detect a valid pid file and not start the service. However, we don't want to have to start/stop celery ourself, we want the uwsgi to manage it so that we get warm shutdown behavior instead of just killing the daemon.

If you use attach-daemon it will send the shutdown signal and exit. My tests show that this does execute a warm, shutdown.

If you use smart-attach-daemon it will not send a shutdown, you have to manage it yourself, not what we want.

if you use smart-attach-daemon2 it will allow you to configure what you do on certain events.

The objective here is to prevent a hard shutdown where the process just dies. For celery, we want to wait for the app to finish running any tasks and then exit. Therefore, I still think smart-attach-daemon2 is the correct thing to stick with since it gives us greater flexibility and is already setup.