How do I restart celery workers gracefully?

前端 未结 7 1733
别跟我提以往
别跟我提以往 2020-12-07 13:47

While issuing a new build to update code in workers how do I restart celery workers gracefully?

Edit: What I intend to do is to something like this

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 14:28

    I have repeatedly tested the -HUP solution using an automated script, but find that about 5% of the time, the worker stops picking up new jobs after being restarted.

    A more reliable solution is:

    stop
    start

    which I have used hundreds of times now without any issues.

    From within Python, you can run:

    import subprocess
    service_name = 'celery_service'
    for command in ['stop', 'start']:
        subprocess.check_call(command + ' ' + service_name, shell=True)
    

提交回复
热议问题