2017-04-06 44 views
1

我們正在使用芹菜與我們的燒瓶應用程序。我們的各種任務有很多隊列,我們​​使用supervisord來運行隊列。我們使用cloudamqp 代理。如何爲芹菜的每個節點命名

實例主管的配置如下圖所示:

[program:my-queue] 
command=/home/ubuntu/opt/proect/venv/bin/celery -A async_runner worker -Q my_queue --loglevel=INFO --without-gossip --without-mingle --autoscale=1,1 -c 1 
environment=PYTHONPATH=/home/ubuntu/opt/project/,PRODUCTION_ENVIRONMENT=true 
directory=/home/ubuntu/opt/project/app 

process_name = %(program_name)s_%(process_num)02d 
user=ubuntu 
numprocs=2 
autostart=true 
autorestart=true 
startsecs=10 
stopwaitsecs = 600 
priority=998 

我們得到以下錯誤和隊列只是停止。

[2017-04-06 12:43:06,759: WARNING/MainProcess] /home/ubuntu/opt/project/venv/local/lib/python2.7/site-packages/kombu/pidbox.py:75: UserWarning: A node named [email protected] is already using this process mailbox! 

Maybe you forgot to shutdown the other node or did not do so properly? 
Or if you meant to start multiple nodes on the same host please make sure 
you give each node a unique node name! 

    warnings.warn(W_PIDBOX_IN_USE.format(node=self)) 

問題:如何給每個節點命名?

當我運行celery -A async_runner status它給5個節點的在線消息。

[email protected]_value_here-: OK 
[email protected]_value_here-: OK 
[email protected]_value_here-: OK 
[email protected]_value_here-: OK 
[email protected]_value_here-: OK 

5 nodes online. 

回答

1

下面是我們如何爲我們公司的每個隊列運行一名芹菜工作者。入口點包含此:

echo QUEUES: ${QUEUES} # comma separated list of queue names 
export NUM_QUEUES=$(python -c "print len('$QUEUES'.split(','))") 
echo NUM_QUEUES: ${NUM_QUEUES} 

supervisord & 

監督者的配置文件中有這樣的:

[program:worker] 
command=/path/to/celery_worker.sh %(process_num)s 
# supervisor uses the special ENV_ prefix to get the environment variable set above 
numprocs=%(ENV_NUM_QUEUES)s 

最後celery_worker.sh包含類似:

QUEUE=$(python -c "print '$QUEUES'.split(',')[$1]") # $1 = process_num above 
celery worker -n "worker.${QUEUE}" -Q ${QUEUE} # -n sets the name of the worker 
+0

不知道我的理解,如果這個回答我的問題。 – Kishan

+0

@soupboy對不起,應該澄清'-n'設置了工人的名字,這聽起來像是你需要的。 –

+0

@soupboy實際上,我現在看到你正在爲同一個隊列運行多個worker,所以你也想在worker名字中包含'process_num'。 –