Django:Celery Worker 没有开始(没有任何错误)
Django: Celery Worker not getting started (without any error)
我正在尝试在 Google Compute Engine
上托管的 Ubuntu 14.04
机器上的 rabbitmq
服务器支持的 Django 应用程序中配置 djcelery
。
尝试使用以下方式在调试模式下启动 celery:python manage.py celery worker -B -E --loglevel=debug
,命令终止,输出如下:
[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 机器上 运行 也是相同的设置,据我所知,我已经在我的云服务器上执行了所有步骤。
附加信息:我验证的事情
- RabbitMQ 服务器 运行 正常。日志文件的输出:
=INFO REPORT==== 24-Mar-2016::17:02:14 === accepting AMQP connection <0.209.0> (127.0.0.1:42326 -> 127.0.0.1:5672)
=INFO REPORT==== 24-Mar-2016::17:02:14 === accepting AMQP connection <0.219.0> (127.0.0.1:42327 -> 127.0.0.1:5672)
=INFO REPORT==== 24-Mar-2016::17:02:17 === accepting AMQP connection <0.229.0> (127.0.0.1:42328 -> 127.0.0.1:5672)
- 端口
5672
在我的机器上打开。我还打开了端口:tcp:5555
、tcp:4369
、tcp:15672
、tcp:5671
,如前所述here(为了安全起见)。
我项目中Celery的配置:
安装了 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)
},
}
)
我终于解决了这个问题。我系统上 celery
和 django-celery
软件包的版本不同。
ubuntu@my-host:~/path/to/project$ pip freeze | grep celery
celery==3.1.21
django-celery==3.1.17
将 celery 版本更改为 3.1.17
修复了它。要更改 pip
的软件包版本,请使用:
ubuntu@my-host:~/path/to/project$ sudo pip install -I celery==3.1.17
我正在尝试在 Google Compute Engine
上托管的 Ubuntu 14.04
机器上的 rabbitmq
服务器支持的 Django 应用程序中配置 djcelery
。
尝试使用以下方式在调试模式下启动 celery:python manage.py celery worker -B -E --loglevel=debug
,命令终止,输出如下:
[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 机器上 运行 也是相同的设置,据我所知,我已经在我的云服务器上执行了所有步骤。
附加信息:我验证的事情
- RabbitMQ 服务器 运行 正常。日志文件的输出:
=INFO REPORT==== 24-Mar-2016::17:02:14 === accepting AMQP connection <0.209.0> (127.0.0.1:42326 -> 127.0.0.1:5672)
=INFO REPORT==== 24-Mar-2016::17:02:14 === accepting AMQP connection <0.219.0> (127.0.0.1:42327 -> 127.0.0.1:5672)
=INFO REPORT==== 24-Mar-2016::17:02:17 === accepting AMQP connection <0.229.0> (127.0.0.1:42328 -> 127.0.0.1:5672)
- 端口
5672
在我的机器上打开。我还打开了端口:tcp:5555
、tcp:4369
、tcp:15672
、tcp:5671
,如前所述here(为了安全起见)。
我项目中Celery的配置:
安装了 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)
},
}
)
我终于解决了这个问题。我系统上 celery
和 django-celery
软件包的版本不同。
ubuntu@my-host:~/path/to/project$ pip freeze | grep celery
celery==3.1.21
django-celery==3.1.17
将 celery 版本更改为 3.1.17
修复了它。要更改 pip
的软件包版本,请使用:
ubuntu@my-host:~/path/to/project$ sudo pip install -I celery==3.1.17