您可以在/etc/supervisor/conf.d/ 中编写您的 celery 任务。为 celery 创建一个新的配置文件,例如 celery.conf。
假设你的 virtualenv 是 venv,你的 django 项目是示例,你的 celery 脚本在 _celery.py
文件应该是这样的
[program:celery]
command=/home/ubuntu/.virtualenvs/venv/bin/celery --app=sample._celery:app worker --loglevel=INFO
directory=/home/ubuntu/sample/
user=ubuntu
numprocs=1
stdout_logfile=/home/ubuntu/logs/celery-worker.log
stderr_logfile=/home/ubuntu/logs/celery-error.log
autostart=true
autorestart=true
startsecs=10
; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600
; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true
; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998
编写完这个主管程序后你需要运行
如果你添加了主管程序,运行这个
$ sudo supervisorctl reread
芹菜:可用
如果您添加/更新主管程序,请运行此
$ sudo supervisorctl update
celery:添加进程组
检查 celery 任务的状态
$ sudo supervisorctl status celery
celery RUNNING pid 18020,正常运行时间 0:00:50
停止 celery 任务
$ sudo supervisorctl stop celery
芹菜:停止
启动 celery 任务
$ sudo supervisorctl start celery
芹菜:开始
重新启动 celery 任务(这将停止并再次启动指定的任务)
$ sudo supervisorctl restart celery
芹菜:停止
芹菜:开始