python - Django:Celery Worker 未启动(没有任何错误)

标签 python django celery django-celery djcelery

我正在尝试在托管于 Google Compute Engine 上的 Ubuntu 14.04 计算机上的 rabbitmq 服务器支持的 Django 应用程序中配置 djcelery .

尝试使用以下命令在 Debug模式下启动 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 计算机上运行,​​据我所知,我已在云服务器上执行了所有步骤。


其他信息:我验证的内容

  1. 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: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)
            },
        }
    )
    

    最佳答案

    我终于能够解决这个问题了。我的系统上的 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
    

    关于python - Django:Celery Worker 未启动(没有任何错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36206825/

    相关文章:

    django - 为什么 django-sphinx 只输出 20 个结果?我怎样才能得到剩下的?

    python - 带有 Django 的 RabbitMQ/Celery 在延迟/就绪/等时挂起 - 没有有用的日志信息

    django - 在 ModelAdmin 中添加代码片段

    python - 如何将 pymysql 与 gevent 和 django-celery 一起使用?

    python - Django celery : Passing request Object to worker

    python - pandas 按一天中的时间分组,每组 15 分钟

    python - Matplotlib:我怎么知道正在使用哪个颜色图?

    python - 我应该如何清理多个 python 困惑?

    python - 在 Python 上根据相等条件添加列表的第二个元素

    django - 在 django 中使用 celery 和 ffmpeg 转码视频