我关注:Putting RQ under supervisor
我的工作:
@job("default")
def send_mail(subject, body, sender, receivers, cc=None, bcc=None, content_type='plain', class_name=None):
"""Send email to users."""
*code to send mail.*
当我跑步时
python manage.py rqworker
我可以使用rq队列执行任务。 但不是与supervisord配置。 Supervisord配置:
路径:/etc/supervisord/conf.d/filename.conf
[program:myworker]
; Point the command to the specific rq command you want to run.
; If you use virtualenv, be sure to point it to
; /path/to/virtualenv/bin/rq
; Also, you probably want to include a settings module to configure this
; worker. For more info on that, see http://python-rq.org/docs/workers/
command= /home/user/.virtualenvs/my_project/bin/rq worker
process_name=%(program_name)s
stdout_logfile = /var/log/my_project/redis.log
; If you want to run more than one worker instance, increase this
numprocs=1
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/user/github_my_projects/projects/my_project
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
答案 0 :(得分:3)
回答我自己的问题。
所以这是我在本地和开发服务器中使用的示例配置。 您可以使用以下命令创建此文件:
sudo touch /etc/supervisor/conf.d/djangorq.conf
开发服务器的配置:
[program:djangorq]
command=/root/.virtualenvs/my_project/bin/rqworker
stdout_logfile=/var/log/my_project/redis.log
user=root
numprocs=1
directory=/var/www/cast-core/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/var/www/projects/my_project
stopsignal=TERM
; These are up to you
autostart=true
autorestart=true
对于当地环境:
[program:myworker]
command= /home/user/.virtualenvs/my_project/bin/rqworker
stdout_logfile = /var/log/my_project/redis.log
numprocs=1
directory=/home/user/github_projects/projects/my_project
environment=DJANGO_CONFIGURATION=Local,DJANGO_SETTINGS_MODULE=config.local,PYTHONPATH=/home/user/github_projects/cast-core/my_project
user = root
stopsignal=TERM
autostart=true
autorestart=true
在此之后,您将启动主管和supervisorctl
sudo service supervisor start
然后
supervisorctl reload
然后使用以下方法将作业排入队列:
send_mail.delay(#params_required_for_send_mail_method)
答案 1 :(得分:2)
我这样解决了。
首先是我的supervisord.conf(将它放在/ etc / supervisor /中)。默认情况下的主要更改是将日志文件放在我可以管理它们的位置(即我的其他日志文件所在的位置)
; supervisor config file
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
[supervisord]
logfile=/home/ubuntu/backend/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/home/ubuntu/backend/logs/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/home/ubuntu/backend/logs/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
运行rqworks的配置如下所示:(放在文件/etc/supervisor/conf.d/rqworker.conf中)。对于此文件,请注意目录。我还将用户更改为运行我的网站的用户:
[program:rqworker]
command= /home/ubuntu/backend/opt/api/deploy_env/bin/python manage.py rqworker
process_name=%(program_name)%(process_num)s
; If you want to run more than one worker instance, increase this
numprocs=2
user=ubuntu
; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/home/ubuntu/backend/opt/api/django_project/
; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM
autostart=true
autorestart=true