我有一个需要与Celery一起运行的Django应用程序(名为pcycler)。我正在尝试使用Supervisor在生产中部署它。

运行时出现错误:


  主管开始芹菜


这给了我:


  芹菜:错误(异常终止)


这是我的celery.conf文件,该文件在启动时包含在supervisor.conf中。

[program:celery]
command=/webapps/pcyclerenv/bin/celery -A pcycler worker -l info

directory=/webapps/pcyclerenv/pcycler
user=pcycleruser
numprocs=1
stdout_logfile=/webapps/pcyclerenv/logs/celeryd_stdout.log
stderr_logfile=/webapps/pcyclerenv/logs/celeryd_stderr.log
redirect_stderr=false
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600
killasgroup=true
priority=998


celeryd_stderr.log的内容是:

Traceback (most recent call last):
  File "/webapps/pcyclerenv/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
    main()
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 81, in main
    cmd.execute_from_commandline(argv)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 769, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 304, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 464, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 484, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/app/utils.py", line 222, in find_app
    sym = symbol_by_name(app, imp=imp)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 487, in symbol_by_name
    return symbol_by_name(name, imp=imp)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/kombu/utils/__init__.py", line 92, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
    return imp(module, package=package)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named pcycler


自然,我决定亲自运行该程序,看看是否可以复制此错误:

pcycleruser@raspberrypi:/webapps/pcyclerenv/pcycler$ pwd
/webapps/pcyclerenv/pcycler

pcycleruser@raspberrypi:/webapps/pcyclerenv/pcycler$ /webapps/pcyclerenv/bin/celery -A pcycler worker -l info

(... text and pickle deprecation warnings ...)

[2014-05-23 14:52:36,053: WARNING/MainProcess] /webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/fixups/django.py:233: UserWarning: Using settings.DEBUG leads to a memory leak, never use this setting in production environments!
  warnings.warn('Using settings.DEBUG leads to a memory leak, never '

[2014-05-23 14:52:36,066: WARNING/MainProcess] celery@raspberrypi ready.


这样行得通。但是,当我在错误的目录中时,如下所示:

pcycleruser@raspberrypi:/webapps/pcyclerenv/pcycler$ cd ..

pcycleruser@raspberrypi:/webapps/pcyclerenv$ pwd
/webapps/pcyclerenv

pcycleruser@raspberrypi:/webapps/pcyclerenv$ /webapps/pcyclerenv/bin/celery -A pcycler worker -l info

Traceback (most recent call last):
  File "/webapps/pcyclerenv/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/webapps/pcyclerenv/local/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
    main()

(... exact same error as above ...)

ImportError: No module named pcycler


我得到与错误日志中完全相同的错误!这使我假设我在超级用户中运行时目录未正确更改。

tldr:当我使用supervisorctl运行命令时,为什么没有应用supervisor.conf中的目录?

最佳答案

发现错误,这真的很愚蠢。

Supervisor conf文件是特定于订单的,因此请执行以下操作:

[program:celery]
directory=/webapps/pcyclerenv/pcycler
command=/webapps/pcyclerenv/bin/celery -A pcycler worker -l info
(... the rest ..)


解决我遇到的问题。

关于python - 主管目录未传播到Celery程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23838306/

10-16 17:12