2016-07-22 34 views
2
Arbeits

Ich bin folgende: Putting RQ under supervisorSupervisord Konfiguration für Django rq nicht

Mein Beruf:

@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.* 

Wenn ich laufen

Python manage.py rqworker

I bin in der Lage, Aufgaben mit rq-Warteschlangen auszuführen. Aber nicht mit Supervisord Konfiguration. Supervisord Konfiguration:

Pfad: /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

Ist der Service laufen und laufen? Was ist die Ausgabe von 'supervisorctl status'? Haben Sie die Protokolldatei (en) überprüft? Außerdem: Sie verwenden die systemweite supervisord Konfiguration ohne 'user =' Konfiguration, so dass Ihr rq worker jetzt als root ausgeführt wird. Ich bin mir ziemlich sicher, dass du das nicht wolltest. – dhke

+0

Ok, also läuft "supervisorctl status myworker". Ich werde Benutzerdetails hinzufügen. Aber die Logdatei hat: Verbindung zu localhost: 6379. Verbindung abgelehnt – Kishan

Antwort

2

meine eigene Frage zu beantworten.

Also hier ist die Beispielkonfiguration, die ich in lokalen und Entwicklungsservern verwendet. Sie diese Datei erstellen können mit:

sudo touch /etc/supervisor/conf.d/djangorq.conf

Konfiguration für Entwicklungsserver:

[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 

Für die lokale Umgebung:

[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 

Danach starten Sie Supervisor und supervisorctl

und dann

supervisorctl reload

Dann enqueue Sie freie Stellen mit:

send_mail.delay(#params_required_for_send_mail_method)

1

ich es auf diese Weise gelöst.

Zuerst meine supervisord.conf (place es in/etc/supervisor /). die wichtigste Änderung von Standard ist die Log-Dateien an einem Ort zu bringen, wo ich sie verwalten kann (also dort, wo meine anderen Protokolldateien)

; 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 

die Config rqworks sieht wie folgt auszuführen: (Ort in der Datei/etc /supervisor/conf.d/rqworker.conf). Für diese Datei achten Sie auf die Verzeichnisse. Ich änderte auch den Benutzer zum selben, der meine Web site laufen lässt:

[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