【问题标题】:Django: Celery Worker not getting started (without any error)Django:芹菜工人没有开始(没有任何错误)
【发布时间】:2016-07-12 10:26:55
【问题描述】:

我正在尝试在我的 Django 应用程序中配置 djcelery,该应用程序由 Ubuntu 14.04 托管在 Google Compute Engine 上的机器上的 rabbitmq 服务器支持。

在尝试使用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 机器上运行,据我所知,我已按照云服务器上的所有步骤进行操作。


其他信息:我验证的内容

  1. RabbitMQ 服务器运行良好。日志文件的输出:

=INFO REPORT==== 24-Mar-2016::17:02:14 === 接受 AMQP 连接 (127.0.0.1:42326 -> 127.0.0.1:5672)

=INFO REPORT==== 24-Mar-2016::17:02:14 === 接受 AMQP 连接 (127.0.0.1:42327 -> 127.0.0.1:5672)

=INFO REPORT==== 24-Mar-2016::17:02:17 === 接受 AMQP 连接 (127.0.0.1:42328 -> 127.0.0.1:5672)

  1. 端口5672 在我的机器上打开。我还打开了端口:tcp:5555tcp:4369tcp:15672tcp:5671,正如提到的here(为了更安全)。

我项目中 Celery 的配置

安装了celerydjango-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)
        },
    }
)

【问题讨论】:

    标签: python django celery django-celery djcelery


    【解决方案1】:

    最后我能够解决这个问题。我系统上celerydjango-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
    

    【讨论】:

      猜你喜欢
      • 2021-09-23
      • 2023-04-06
      • 2016-09-12
      • 2019-08-01
      • 2012-11-13
      • 2017-05-10
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      相关资源
      最近更新 更多