celery shutdown worker after particular task

后端 未结 3 2025
遥遥无期
遥遥无期 2021-02-07 00:25

I\'m using celery (solo pool with concurrency=1) and I want to be able to shut down the worker after a particular task has run. A caveat is that I want to avoid any possibility

3条回答
  •  礼貌的吻别
    2021-02-07 00:58

    If you need to shutdown a specific worker and don't know it's name in advance, you can get it from the task properties. Based on the answers above, you can use:

    app.control.shutdown(destination=[self.request.hostname])
    

    or

    app.control.broadcast('shutdown', destination=[self.request.hostname])
    

    Note:

    • A worker should be started with a name (option '-n');
    • The task should be defined with bind=True parameter.

提交回复
热议问题