我正在尝试在djcelery
上托管的rabbitmq
计算机上的Ubuntu 14.04
服务器支持的Django应用中配置Google Compute Engine
。
尝试使用:python manage.py celery worker -B -E --loglevel=debug
在调试模式下启动celery时,命令将以下面的输出终止:
[2016-03-24 12:16:09,568: DEBUG/MainProcess] | Worker: Preparing bootsteps.
[2016-03-24 12:16:09,571: DEBUG/MainProcess] | Worker: Building graph...
[2016-03-24 12:16:09,572: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Queues (intra), Pool, Autoscaler, StateDB, Autoreloader, Beat, Consumer}
[2016-03-24 12:16:09,575: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
[2016-03-24 12:16:09,576: DEBUG/MainProcess] | Consumer: Building graph...
[2016-03-24 12:16:09,577: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Agent, Heart, Gossip, event loop}
<user>@<gce.host>:~/path/to/my/project$
可能导致此问题的原因是什么? 在我的本地ubuntu机器上运行相同的设置,据我所知,我已经按照我的云服务器上的所有步骤进行操作。
其他信息:我验证的内容
= INFO REPORT ==== 2016年3月24日:: 17:02:14 ===接受AMQP连接&lt; 0.209.0&gt; (127.0.0.1:42326 - &gt; 127.0.0.1:5672)
= INFO REPORT ==== 2016年3月24日:: 17:02:14 ===接受AMQP连接&lt; 0.219.0&gt; (127.0.0.1:42327 - &gt; 127.0.0.1:5672)
= INFO REPORT ==== 2016年3月24日:: 17:02:17 ===接受AMQP连接&lt; 0.229.0&gt; (127.0.0.1:42328 - &gt; 127.0.0.1:5672)
5672
。我还打开了端口:tcp:5555
,tcp:4369
,tcp:15672
,tcp:5671
,如前所述[{3}}(更安全的一面)。我项目中的芹菜配置:
已安装的celery
和django-celery
包。创建rabbitMQ
用户并使用命令设置其权限:
sudo rabbitmqctl add_user <user> <password>
sudo rabbitmqctl set_permissions -p / <user> ".*" ".*" ".*"
在 settings.py 文件中,我添加了:
import djcelery
djcelery.setup_loader()
MIDDLEWARE_CLASSES = [ 'django.middleware.transaction.TransactionMiddleware',
..]
INSTALLED_APPS = ['djcelery',
..]
celery.py 的内容如下:
from __future__ import absolute_import
import os
from datetime import timedelta
from celery import Celery
from celery.schedules import crontab
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<my_project>.settings')
app = Celery('<my_project>')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('<my_project>.settings')
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(
CELERY_ACCEPT_CONTENT = ['json'],
CELERY_TASK_SERIALIZER = 'json',
CELERY_RESULT_SERIALIZER = 'json',
BROKER_URL = 'amqp://<user>:<password>@localhost:5672//',
# BROKER_URL = 'django://',
CELERY_RESULT_BACKEND = "amqp",
CELERY_IMPORTS = ("<module1>.tasks", "<module2>.tasks.tasks", "<module3>.tasks.tasks"),
CELERY_ALWAYS_EAGER = False,
# CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
# CELERY_TIMEZONE = 'Europe/London'
CELERY_TIMEZONE = 'UTC',
CELERYBEAT_SCHEDULE = {
'debug-test': {
'task': '<module1>.tasks.test_celery',
'schedule': timedelta(seconds=5),
# 'args': (1, 2)
},
}
)
答案 0 :(得分:3)
最后我能解决这个问题。我系统上celery
和django-celery
包的版本不同。
ubuntu@my-host:~/path/to/project$ pip freeze | grep celery
celery==3.1.21
django-celery==3.1.17
将芹菜版本更改为3.1.17
修复它。要更改pip
的软件包版本,请使用:
ubuntu@my-host:~/path/to/project$ sudo pip install -I celery==3.1.17