Using celeryd as a daemon with multiple django apps?

后端 未结 2 1144
难免孤独
难免孤独 2021-02-05 07:14

I\'m just starting using django-celery and I\'d like to set celeryd running as a daemon. The instructions, however, appear to suggest that it can be configured for only one site

2条回答
  •  长发绾君心
    2021-02-05 07:57

    Did not try but using Celery 3.1.x which does not need django-celery, according to the documentation you can instantiate a Celery app like this:

    app1 = Celery('app1')
    
    app1.config_from_object('django.conf:settings')
    app1.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
    
    
    @app.task(bind=True)
    def debug_task(self):
        print('Request: {0!r}'.format(self.request))
    

    But you can use celery multi for launching several workers with single configuration each, you can see examples here. So you can launch several workers with different --app appX parameters so it will use different taks and settings:

    # 3 workers: Two with 3 processes, and one with 10 processes.
    $ celery multi start 3 -c 3 -c:1 10
    celery worker -n celery1@myhost -c 10 --config celery1.py --app app1
    celery worker -n celery2@myhost -c 3  --config celery2.py --app app2
    celery worker -n celery3@myhost -c 3  --config celery3.py --app app3
    

提交回复
热议问题