如何将CELERY放到后台执行?

戏子无情 提交于 2020-02-09 18:33:27

在作正式环境,这个是必须的。

于是找了两小时文档,

以下这个方法,相对来说好实现。

就是要注意supervisord.conf的目录存放位置。

放在DJANGO的PROJ目录下,是最佳位置。

 

 

https://thomassileo.name/blog/2012/08/20/how-to-keep-celery-running-with-supervisor/

如何你不幸的和我一样,无法PIP只能用setup.py的话,可能celery和supervisord都要用绝对目录

[program:celeryd]
command=/usr/local/python27/bin/celery worker --app=ism -c 4 -l info
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

  

~~~~~~~~~~~~~~~~

How to keep Celery running with supervisor

Supervisor is a Python program that allows you to control and keep running any unix processes. It can also restart crashed processes. I use it to make sure Celery workers are always running.

I'm using virtualenv, Celery 3.0.5, and supervisor 3.0. I'm assuming Celery is already installed and configured.

Installation

First, you need to install supervisor in your virtualenv and generate a configuration file.

I store a supervisord.conf config file at the root of each project, and also, be careful to use theabsolute path to the Python interpreter of the virtualenv.

$ pip install supervisor
$ cd /path/to/your/project
$ echo_supervisord_conf > supervisord.conf

Next, just add this section after the [supervisord] section:

[program:celeryd]
command=/home/thomas/virtualenvs/yourvenv/bin/celery worker --app=myapp -l info 
stdout_logfile=/path/to/your/logs/celeryd.log
stderr_logfile=/path/to/your/logs/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

It's a simplified version of the Celery supervisor example configuration file, adapted to work with virtualenvs.

Usage

Just run supervisord in your project directory.

$ supervisord

Then, you can use the supervisorctl command to enter the interactive shell. Type help to get started. You can also execute supervisor command directly:

$ supervisorctl tail celeryd
$ supervisorctl restart celeryd

And you ?

If you have any tips or suggestions, don't hesitate !

~~~~~~~~~~~~~~~

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!