2

I am trying to configure djcelery in my Django Application backed by rabbitmq server on Ubuntu 14.04 machine hosted on Google Compute Engine.

On attempt to start celery in debug mode using: python manage.py celery worker -B -E --loglevel=debug, command is getting terminated with below output:

[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$

What can possibly be the cause of this issue? The same setup is running on my local ubuntu machine and as far as I remember, I have followed all the steps on my cloud server.


Additional Info: Things I verified

  1. RabbitMQ server is running fine. Output from log file:

=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)

  1. Port 5672 is open on my machine. I have also opened port: tcp:5555, tcp:4369, tcp:15672, tcp:5671 as is mentioned here (to be on the safer side).

Celery's Configuration in my project:

Installed celery and django-celery package. Created rabbitMQ user and set its permissions with commands:

sudo rabbitmqctl add_user <user> <password>
sudo rabbitmqctl set_permissions -p / <user> ".*" ".*" ".*"

In settings.py file, I have added:

import djcelery
djcelery.setup_loader()

MIDDLEWARE_CLASSES = [ 'django.middleware.transaction.TransactionMiddleware',
                       ..]

INSTALLED_APPS = ['djcelery',
                  ..]

Content of celery.py is as:

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)
        },
    }
)

1 Answer 1

3

Finally I was able to fix this. The version of celery and django-celery package on my system were different.

ubuntu@my-host:~/path/to/project$ pip freeze | grep celery
celery==3.1.21
django-celery==3.1.17

Changing celery version to 3.1.17 fixed it. To change the pip's package version, use:

ubuntu@my-host:~/path/to/project$ sudo pip install -I celery==3.1.17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.