使用supervisord启动Celery:AttributeError:'module'对象没有属性'celery'

时间:2013-06-09 06:36:48

标签: celery daemon supervisord attributeerror

我曾经将我的所有Flask应用程序代码和芹菜代码放在一个文件中,并且它与主管一起运行良好。但是,它很头发,所以我将我的任务分成celery_tasks.py,这个问题就出现了。

在我的项目目录中,我可以使用以下命令手动启动芹菜

celery -A celery_tasks worker --loglevel=INFO

但是,因为这是一个服务器,我需要celery在后台运行作为守护进程。 但是当我调用sudo supervisorctl restart celeryd

时,它会显示以下错误
celeryd: ERROR (abnormal termination)

并且日志说:

Traceback (most recent call last):
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/bin/celery", line 9, in <module>
    load_entry_point('celery==3.0.19', 'console_scripts', 'celery')()
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/__main__.py", line 14, in main
    main()
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 957, in main
    cmd.execute_from_commandline(argv)
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/bin/celery.py", line 901, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 185, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 300, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/srv/www/learningapi.stanford.edu/peerAPI/peerAPIenv/local/lib/python2.7/site-packages/celery/bin/base.py", line 318, in find_app
    return sym.celery
AttributeError: 'module' object has no attribute 'celery'

我使用了以下配置。

[program:celeryd]
command = celery -A celery_tasks worker --loglevel=INFO

user=peerapi
numprocs=4

stdout_logfile = <path to log>
stderr_logfile = <path to log>
autostart = true
autorestart = true
environment=PATH="<path to my project>"

startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

我的代码也正确地初始化

celery = Celery('celery_tasks', broker='amqp://guest:guest@localhost:5672//',
                backend='amqp')
celery.config_from_object(celeryconfig)

我的celeryconfig.py正常工作

CELERY_TASK_SERIALIZER='json'
CELERY_RESULT_SERIALIZER='json'
CELERY_TIMEZONE='America/Los Angeles'
CELERY_ENABLE_UTC=True

有任何线索吗?

1 个答案:

答案 0 :(得分:0)

看起来您的应用程序找不到您的celeryconfig,因为您没有设置CWD,例如。尝试使用类似的东西:   cd app_path;芹菜...... 您还需要设置env

# local settings
PATH=/home/ubuntu/envs/app/bin:$PATH
PYTHONHOME=/home/ubuntu/envs/app/
PYTHONPATH=/home/ubuntu/projects/app/

应该有效。