domingo, 10 de junio de 2012

heroku django celery redistogo

If you want to use redistogo as a backend and broker for django celery

These are the relevant lines on settings.py

import os
if [(i,k) for i,k in os.environ.items() if 'heroku' in k]: #detect heroku somehow reliably
    REDIS_DB = 0
    REDIS_CONNECT_RETRY = True
    CELERY_RESULT_BACKEND = 'redis'
    CELERY_REDIS_PORT = 9104
    CELERY_REDIS_PASSWORD = '93a4b2c92dc0e07f0f9c82e806108fc1'
    CELERY_REDIS_HOST = 'gar.redistogo.com'
    BROKER_URL = os.getenv('REDISTOGO_URL', 'redis://localhost')
    BROKER_TRANSPORT = 'redis'
    BROKER_BACKEND = 'redis'
    BROKER_PORT = CELERY_REDIS_PORT
    BROKER_HOST = CELERY_REDIS_HOST
    BROKER_VHOST = '/'
    BROKER_PASSWORD = CELERY_REDIS_PASSWORD
    CELERYD_CONCURRENCY = 1
    CELERY_RESULT_PORT = 9104
    CELERY_TASK_RESULT_EXPIRES = 60 * 10

 
import djcelery
djcelery.setup_loader() #not sure if needed

Dont forget to add your celery worker on the Procfile
web: bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT name_of_your_project/settings.py;
worker: bin/python name_of_your_project
/manage.py celeryd -E -B --loglevel=INFO




And turn in it on
heroku ps:scale worker=1
And then you can test it if it works
heroku run name_of_your_project/manage.py shell
from your_app.tasks import task_name
result = task_name.apply_async(args=[arg1,arg2])
result.wait()

Please leave a comment if you have problems with this, i'm more than glad to help because i suffered this. Doesnt matter if its a year or many months later leave a comment i'll be here.

No hay comentarios:

Publicar un comentario