django + celery + uwsgi没有主管

时间:2015-08-03 15:42:00

标签: django celery uwsgi django-celery

在开发服务器上,Django与celery和django-celery合作得很好:

python manage.py runserver
celery -A backup worker -l info -B
celerycam --frequency=10.0

在生产服务器上,我试图用:

运行芹菜
[uwsgi]
...
master = True
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker -l info -B
smart-attach-daemon = ${path}/${name_project}/.env/bin/python ${path}/manage.py celerycam --frequency=10.0

但它不起作用。 如何在没有使用主管的情况下运行它?

更新

它没有看到Django,但该网站有效。在日志uwsgi中:

Mon Aug  3 16:10:57 2015 - spawned uWSGI master process (pid: 23462)
Mon Aug  3 16:10:57 2015 - spawned uWSGI worker 1 (pid: 23666, cores: 1)
Mon Aug  3 16:10:57 2015 - spawned uWSGI worker 2 (pid: 23667, cores: 1)
Mon Aug  3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celery -A backup worker -l info -B"
Mon Aug  3 16:10:57 2015 - [uwsgi-daemons] spawning "/home/1/2/3/manage.py celerycam --frequency=10.0"
Traceback (most recent call last):
  File "/home/1/2/3/manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Traceback (most recent call last):
  File "/home/1/2/3/manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Mon Aug  3 16:10:58 2015 - subprocess 23668 exited with code 1
Mon Aug  3 16:10:58 2015 - subprocess 23669 exited with code 1

manage.py:

 #!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backup.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

2 个答案:

答案 0 :(得分:2)

您可以使用attach-daemonsmart-attach-daemon。但是如果您使用的是smart-attach-daemon,那么您也应该使用pid文件启动芹菜并在uwsgi中设置它的路径:

smart-attach-daemon = ${path}/${name_project}/var/celery-worker.pid ${path}/${name_project}/.env/bin/python ${path}/manage.py celery -A test worker --pidfile=${path}/${name_project}/var/celery-worker.pid  -l info -B

答案 1 :(得分:1)

在“attach-daemon”上替换“smart-attach-daemon”