python - Django rq 的 Supervisord 配置不起作用

标签 python django supervisord

我正在关注: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 配置。 主管配置:

路径:/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

最佳答案

回答我自己的问题。

下面是我在本地和开发服务器中使用的示例配置。 您可以使用以下方法创建此文件:

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

在此之后你开始supervisor和supervisorctl

sudo 服务主管启动

然后

supervisorctl 重新加载

然后使用 :

将您的工作排入队列

send_mail.delay(#params_required_for_send_mail_method)

关于python - Django rq 的 Supervisord 配置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38520957/

相关文章:

javascript - Dotcloud Nodejs Supervisord.conf 不工作

Docker、Supervisord 和 supervisor-stdout

python - 作为非根用户的主管

python - 我应该将Python的pyc文件添加到.dockerignore吗?

Python 格式 timedelta 大于 24 小时以显示仅包含小时数?

django - 将 Django-rest-framework 与 Django View 一起使用是否正确

django - 如何同时提交表单和表单集

python - 从 XBee 接收的 pySerial 数据未正确显示

python - Numpy where() 使用随数组中项目位置而变化的条件

Django 收到错误 :send_mail() got an unexpected keyword argument 'fail_silently' on sending mails