动态添加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任务,将启动新增加的任务