问题描述
我曾经将我所有的Flask应用程序代码和celery代码存储在一个文件中,并且在主管的支持下工作得很好.但是,由于头发很长,所以我将任务拆分为celery_tasks.py,就会发生此问题.
I used to have all my Flask app code and celery code in one file and it worked fine with supervisor. However, it is very hair so I split my tasks to celery_tasks.py and this problem occurs.
在我的项目目录中,我可以使用以下命令手动启动celery
In my project directory, I can start celery manually with the following command
celery -A celery_tasks worker --loglevel=INFO
但是,由于这是服务器,因此我需要celery在后台作为守护程序运行.但是当我调用sudo supervisorctl restart celeryd
However, because this is a server, I need celery to run as a daemon in background.But it shows following error when I called 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
我的代码也正确初始化了芹菜
My code also init celery properly
celery = Celery('celery_tasks', broker='amqp://guest:guest@localhost:5672//',
backend='amqp')
celery.config_from_object(celeryconfig)
我的celeryconfig.py正常工作
and my celeryconfig.py is working normally
CELERY_TASK_SERIALIZER='json'
CELERY_RESULT_SERIALIZER='json'
CELERY_TIMEZONE='America/Los Angeles'
CELERY_ENABLE_UTC=True
有任何线索吗?
推荐答案
好像您的应用程序找不到celeryconfig,它的发生是因为未设置CWD.尝试使用类似: cd app_path;芹菜另外,您需要设置环境
Looks like your application can't find your celeryconfig, it happens because you CWD is not set for example. Try to use something like: cd app_path; celeryd ...Also you need to setup env
# local settings
PATH=/home/ubuntu/envs/app/bin:$PATH
PYTHONHOME=/home/ubuntu/envs/app/
PYTHONPATH=/home/ubuntu/projects/app/
应该工作.
这篇关于以有监督者身份启动Celery:AttributeError:“模块"对象没有属性"celery"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!