3

Ok, I got everything installed properly to get celery + redis in django

I got

INSTALLED_APPS = (
    'djcelery',
    'kombu.transport.django',
)

These are in my settings

CELERY_REDIS_HOST = 'localhost'
CELERY_REDIS_PORT = 8889
CELERY_REDIS_DB = 0
CELERY_RESULT_BACKEND = 'redis'

BROKER_URL = "redis://localhost:8889/0"

REDIS_CONNECT_RETRY = True
CELERY_IGNORE_RESULT = True
CELERY_SEND_EVENTS = True
CELERY_TASK_RESULT_EXPIRES = 60
CELERYBEAT_SCHEDULER= 'djcelery.schedulers.DatabaseScheduler'

I got redis working with

./redis-server

It outputs to the terminal every second or so I can also run

./manage.py celeryd -E -B --loglevel=INFO -n w1.d820

Without errors I can even see my tasks being added and successfully finished with

./manage celeryev

So even thought it gets logged by celeryev this code doesnt work:

from celery.task import task
@task
def add(x, y):
    return x + y

res = add.apply_async(args=[1,5])
print res.wait()

It just hangs without ever returning the result, I can see its actually trying to get it from redis because if I do

./redis-cli
MONITOR

I get lots of GETs trying to get an non existance key So my conclusion is that django is not saving to the backend Whats wrong with my settings? I think Iam missing something obvious and I can't see it because I've been too long fighting this. Help

Btw I can't use the standard port 6379 because I am on a shared server.

UPDATE using these

celery==2.5.3
django-celery==2.5.5
django-celery-with-redis==2.5

4 Answers 4

7

Do you have import djcelery; djcelery.setup_loader() in your settings.py?

You can find out where it is trying to connect by running the following:

 $ python manage.py celeryctl shell

 >>> celery.broker_connection().as_uri()

The 'setup_loader' is very important, so you must make sure that you include it.

(the good news is that celery will support Django out of the box for version 2.7).

Sign up to request clarification or add additional context in comments.

1 Comment

i did have those lines in my settings. +1 for how to know where is trying to connect celery.
4

In ubuntu 10.10 when you install redis it automatically starts at boot, and it was conflicting with celery because apparently even if you tell it to use this or that port if celery can connect to redis in 6379 port it will use it as a backend. I've not seen the code but is my conclusion. So i closed all the redis instances ran my own with my redis.conf on whatever port i want and then i put these on my settings.

BROKER_URL = 'redis://localhost:8889/0'
REDIS_DB = 0
REDIS_CONNECT_RETRY = True
CELERY_RESULT_BACKEND = 'redis'
CELERY_REDIS_PORT = 8889
BROKER_PORT = 8889
CELERY_RESULT_PORT = 8889
CELERY_TASK_RESULT_EXPIRES = 10
CELERYBEAT_SCHEDULER= 'djcelery.schedulers.DatabaseScheduler'

Comments

0

What version of celery are you using? In the development version it looks like they use a different Decorator;

from celery.task import task

@celery.task()
def add(x, y):
    return x + y

2 Comments

His decorator is right. Where are you seeing that? That wouldn't even work. You would have to do import celery for this to work.
I took that straight from the development versions example :) See here: celery.github.com/celery/userguide/tasks.html
0

Are you starting the Redis server on the port 8889?

1 Comment

Hmmmm. Try using: add.delay(1, 5) Instead of: add.apply_async(args=[1,5]) See if that works?

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.