Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Celery Settings Import Issue

Im trying to create a celery file and run it via ..

celery -A myapp worker -l info

However Im getting the error,

  File "/production/pythonenv/project/lib/python2.7/site-packages/configurations/base.py", line 30, in __new__
    raise ImproperlyConfigured(install_failure)
django.core.exceptions.ImproperlyConfigured: django-configurations settings importer wasn't correctly installed. Please use one of the starter functions to install it as mentioned in the docs: http://django-configurations.readthedocs.org/

Here are the config/files,

Tree

(run from the project rool via 'tree myapp/ config/')

config/
|-- __init__.py
|-- __init__.pyc
|-- celery.py
|-- settings.py
|-- urls.py
|-- wsgi.py  
myapp/
|-- __init__.py
|-- __init__.pyc
|-- celery.py
|-- helper.py
|-- models.pyc
|-- serializers.py
|-- views.py

celery.py

from __future__ import absolute_import
import os,sys,
from celery import Celery
from django.conf import settings

sys.path.append('/prod/project/')
sys.path.append('/prod/')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')

app = Celery('myapp.celery.celery')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(settings.INSTALLED_APPS, related_name='tasks')

Any ideas ?

like image 385
felix001 Avatar asked May 27 '14 09:05

felix001


1 Answers

According to http://django-configurations.readthedocs.org/en/latest/cookbook/#celery you may need to add in your celery.py:

os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')

from configurations import importer
importer.install()

app = Celery('myapp.celery.celery')
like image 67
Seb D. Avatar answered Sep 30 '22 07:09

Seb D.