In my Django project, I use no SQL database at all, my primary datastore is MongoDB, through mongoengine.
I want to setup Celery to work with Redis as the broker and backend. I installed django-celery-with-redis, installed Redis (locally and in production), and tried to use the following in my settings.py:
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = BROKER_URL
import djcelery
djcelery.setup_loader()
But when I ran the celery process and it received a task to process, when returning the result, it complained with errors that settings.DATABASES was improperly configured. That didn't make much sense since I set CELERY_RESULT_BACKEND to be Redis.
I discovered that djcelery overrides the backend on djcelery.setup_loader()
to database
: see DjangoLoader from the source code.
I struggled to find ways to bypass DjangoLoader's overriding, and the only way I found was by making a duplicate of djcelery/loaders.py and modifying that line:
override_backends = {
'database': 'celery.backends.redis.RedisBackend',
}
Then in my settings.py I do:
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = BROKER_URL
os.environ.setdefault('CELERY_LOADER',
'myproject.utils.ugly_djcelery_hack.DjangoLoader')
Notice no djcelery.setup_loader()
there any more.
This is clearly an ugly hack, is there a more elegant way of doing this?