有监督工人的芹菜不是孤立工作的



.conf file

[program:task1]
    directory=/home/ubuntu/proj1
    command=/usr/bin/python3 /usr/local/bin/celery -A proj1 worker -l info --concurrency=10 -n proj1_worker@%%h
    user=ubuntu
    numprocs=1
    stdout_logfile=/var/log/proj1_celeryd.log
    stderr_logfile=/var/log/proj1_celeryd.log
    autostart=true
    autorestart=true
    startsecs=10
    stopwaitsecs=600
    priority=998
[program:task2]
    directory=/home/ubuntu/proj2/
    command=/usr/bin/python3 /usr/local/bin/celery -A proj2 worker -l info --concurrency=10 -n proj2_worker@%%h
    user=ubuntu
    numprocs=1
    stdout_logfile=/var/log/proj2_celeryd.log
    stderr_logfile=/var/log/proj2_celeryd.log
    autostart=true
    autorestart=true
    startsecs=10
    stopwaitsecs=600
    priority=998
[group:celeryworkers]
programs=task1,task2

proj1_worker和proj2_worker并没有被孤立。起初,总是proj1_worker被称为,即使我称之为proj2_worker

我不知道我哪里出错了。请协助。

提前谢谢你

首先,我真的建议您为每个项目使用virtualenv。创建 2 个单独的虚拟环境(您可以指定自己的位置(,请参阅 https://docs.python.org/3/library/venv.html。

python3 -m venv /home/ubuntu/virtualenvs/proj1
python3 -m venv /home/ubuntu/virtualenvs/proj2

激活虚拟环境并安装芹菜:

source /home/ubuntu/virtualenvs/proj1/bin/activate
pip install --upgrade celery
source /home/ubuntu/virtualenvs/proj2/bin/activate
pip install --upgrade celery

然后,您的主管配置应如下所示:

[program:task1]
    directory=/home/ubuntu/proj1
    command=/home/ubuntu/virtualenvs/proj1/bin/celery worker -A proj1 -l info --concurrency=10 -n proj1_worker@%%h
    # ...
[program:task2]
    directory=/home/ubuntu/proj2
    command=/home/ubuntu/virtualenvs/proj1/bin/celery worker -A proj2 -l info --concurrency=10 -n proj2_worker@%%h
    # ...

接下来,为您的项目创建 2 个单独的虚拟主机:

rabbitmqctl add_user proj_1 <PASSWORD>
rabbitmqctl add_vhost proj_1_vhost
rabbitmqctl set_permissions -p proj_1_vhost proj_1 ".*" ".*" ".*"
rabbitmqctl add_user proj_2 <PASSWORD>
rabbitmqctl add_vhost proj_2_vhost
rabbitmqctl set_permissions -p proj_2_vhost proj_2 ".*" ".*" ".*"

最后修改芹菜配置以使用新创建的虚拟主机:

app = Celery('proj1_celery_app')
app.conf.update(
    # ...
    broker_url='amqp://proj1:<PASSWORD>@localhost:5672/proj_1_vhost'
    # ...
)
app = Celery('proj2_celery_app')
app.conf.update(
    # ...
    broker_url='amqp://proj2:<PASSWORD>@localhost:5672/proj_2_vhost'
    # ...
)

有关兔子vhosts的更多信息,请参阅此SO帖子:在同一台服务器上运行多个芹菜实例。

相关内容

  • 没有找到相关文章

最新更新