How to restart Celery gracefully without delaying tasks

前端 未结 7 529
面向向阳花
面向向阳花 2020-12-24 07:14

We use Celery with our Django webapp to manage offline tasks; some of these tasks can run up to 120 seconds.

Whenever we make any code modifications, we need to rest

7条回答
  •  醉梦人生
    2020-12-24 07:42

    I think you can try this:

    kill -s HUP ``cat /var/run/celeryd.pid`` 
    python manage.py celeryd --pidfile=/var/run/celeryd.pid
    

    HUP may recycle every free worker and leave executing workers keep running and HUP will let these workers be trusted. Then you can safely restart a new celery worker main process and workers. Old workers may be killed itself when task has been finished.

    I've use this way in our production and it seems safe now. Hope this can help you!

提交回复
热议问题