1. 程式人生 > 其它 >動態新增supervisor任務與celery非同步佇列單執行緒序列佇列

動態新增supervisor任務與celery非同步佇列單執行緒序列佇列

技術標籤:supervisor佇列

動態新增supervisor任務與celery非同步序列任務


supervisord多用於服務啟動時開啟多工(依賴任務或服務),celery通常可以指定多worker(多執行緒)併發執行任務,一些特殊情況下任務需要序列執行, 指定單worker即單執行緒非同步任務佇列。如何實現在supervisor中動態的新增celery佇列?

supervisor.conf

開啟supervisord服務
supervisord -n -c /code/mgnt/supervisord.conf

[inet_http_server] 
port=127.0.0.1:9001

[supervisord]
nodaemon=true

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=http://127.0.0.1:9001                 ### supervisor的server—url

[program:redis]
command = /usr/bin/redis-server  /etc/redis.conf
priority=11

[program:app-uwsgi]
command = /usr/local/bin/uwsgi --ini /code/mgnt/uwsgi.ini
priority=110

[program:nginx-app]
command = /usr/sbin/nginx -c /code/mgnt/nginx-app.conf
priority=111

[program:celery]
command = /usr/local/bin/celery --workdir=/code/mgnt/backend --logfile=/var/log/celery.log -A server worker -B -l info
priority=112

[program:django-makemigrations]
command = /usr/local/bin/python3 /code/mgnt/backend/manage.py makemigrations
priority=113

[program:django-migrate]
command = /usr/local/bin/python3 /code/mgnt/backend/manage.py migrate
priority=114

[program:django-collectstatic]
command = /usr/local/bin/python3 /code/mgnt/backend/manage.py collectstatic
priority=115


[program:celery-pool]
command=/usr/local/bin/celery worker -A server  --workdir=/code/mgnt/backend  -c 1 -E  --logfile=/var/log/celery-pool.log  --loglevel=info  -n celery_pool  -Q celery_pool
priorty=116

[program:celery-volume]
command=/usr/local/bin/celery worker -A server  --workdir=/code/mgnt/backend  -c 1 -E  --logfile=/var/log/celery-volume.log  --loglevel=info  -n celery_volume  -Q  celery_volume
priorty=117

[program:celery-target]
command=/usr/local/bin/celery worker -A server  --workdir=/code/mgnt/backend  -c 1 -E  --logfile=/var/log/celery-target.log  --loglevel=info  -n celery_target  -Q celery_target
priorty=118

[program:celery-snapshot]
command=/usr/local/bin/celery worker -A server  --workdir=/code/mgnt/backend  -c 1 -E  --logfile=/var/log/celery-snapshot.log  --loglevel=info  -n celery_snapshot  -Q celery_snapshot
priorty=118

  • -c 開啟的執行緒數
  • -n 佇列名稱
  • -Q 佇列
    單執行緒實現任務的序列

supervisord動態新增佇列

將需要新增的任務寫入supervisor.conf檔案

  • supervisorctl update
    更新supervisor任務,將啟動新增加的任務