Skip to content

Instantly share code, notes, and snippets.

@gciding
Created September 13, 2014 13:30
Show Gist options
  • Save gciding/6935ee400f903ffd4bdc to your computer and use it in GitHub Desktop.
Save gciding/6935ee400f903ffd4bdc to your computer and use it in GitHub Desktop.
# This file lives in the project directory (my_project_name)
from __future__ import absolute_import
from config.celery import app as celery_app
; Called from supervisrod
[program:celeryd]
command=/home/django/.virtualenvs/my_project_name/bin/celery -A my_project_name worker --loglevel=INFO
directory=/var/www/django/my_project_name/
user=django
group=www-data
numprocs=1
stdout_logfile=/var/log/supervisor/celeryd.log
stderr_logfile=/var/log/supervisor/celeryd_error.log
autostart=true
autorestart=true
startsecs=5
environment=DJANGO_SETTINGS_MODULE="config",DJANGO_CONFIGURATION="Local"
; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from .local import Local # noqa
from .production import Production # noqa
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')
from configurations import importer
importer.install()
app = Celery('my_project_name') #this corresponds to the django project name which is the name of the containing directory
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
# Also very similar to production.py (etc)
-*- coding: utf-8 -*-
'''
Local Configurations
- Runs in Debug mode
- Uses console backend for emails
- Use Django Debug Toolbar
'''
from configurations import values
from .common import Common
class Local(Common):
# DEBUG
DEBUG = values.BooleanValue(True)
TEMPLATE_DEBUG = DEBUG
# END DEBUG
# INSTALLED_APPS
INSTALLED_APPS = Common.INSTALLED_APPS
# END INSTALLED_APPS
# [... file continues ...]
Traceback (most recent call last):
File "/home/django/.virtualenvs/my_project_name/bin/celery", line 11, in <module>
sys.exit(main())
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/__main__.py", line 30, in main
main()
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/celery.py", line 769, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/base.py", line 305, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/base.py", line 465, in setup_app_from_commandline
self.app = self.find_app(app)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/base.py", line 485, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/app/utils.py", line 229, in find_app
sym = symbol_by_name(app, imp=imp)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/bin/base.py", line 488, in symbol_by_name
return symbol_by_name(name, imp=imp)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/kombu/utils/__init__.py", line 92, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/home/django/.virtualenvs/my_project_name/local/lib/python2.7/site-packages/celery/utils/imports.py", line 101, in import_from_cwd
return imp(module, package=package)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/www/django/my_project_name/config/__init__.py", line 4, in <module>
from .local import Local # noqa
File "/var/www/django/my_project_name/config/local.py", line 13, in <module>
class Local(Common):
File "/home/django/.virtualenvs/my_project_name/local/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/
@alb3rto269
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment