How to start a Celery worker from a script/module __main__?

前端 未结 5 856
离开以前
离开以前 2020-12-13 07:07

I\'ve define a Celery app in a module, and now I want to start the worker from the same module in its __main__, i.e. by running the module with

5条回答
  •  Happy的楠姐
    2020-12-13 08:00

    Since Celery 5 things have been changed

    The worker_main results now:

    AttributeError: 'Celery' object has no attribute 'worker_main'
    

    For Celery 5 do following:

    app = celery.Celery(
        'project',
        include=['project.tasks']
    )
    
    if __name__ == '__main__':
        worker = app.Worker(
            include=['project.tasks']
        )
        worker.start()
    

    See here celery.apps.worker and celery.worker.WorkController.setup_defaults for details (hope it will be documented better in the future).

提交回复
热议问题