diff --git a/src/.isort.cfg b/src/.isort.cfg index 02c7273d..adcc4815 100644 --- a/src/.isort.cfg +++ b/src/.isort.cfg @@ -1,3 +1,3 @@ [settings] line_length=120 -skip=migrations +skip=migrations,celery.py diff --git a/src/c3nav/celery.py b/src/c3nav/celery.py new file mode 100644 index 00000000..21e95d1a --- /dev/null +++ b/src/c3nav/celery.py @@ -0,0 +1,11 @@ +import os + +from celery import Celery + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'c3nav.settings') + +from django.conf import settings # noqa + +app = Celery('c3nav') +app.config_from_object('django.conf:settings') +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) diff --git a/src/c3nav/settings.py b/src/c3nav/settings.py index aa70a9fe..14c2a837 100644 --- a/src/c3nav/settings.py +++ b/src/c3nav/settings.py @@ -101,6 +101,17 @@ if HAS_MEMCACHED: } SESSION_ENGINE = "django.contrib.sessions.backends.cached_db" +HAS_CELERY_BROKER = config.has_option('celery', 'broker') +if HAS_CELERY_BROKER: + BROKER_URL = config.get('celery', 'broker') + CELERY_RESULT_BACKEND = config.get('celery', 'backend') + CELERY_SEND_TASK_ERROR_EMAILS = bool(ADMINS) +else: + CELERY_ALWAYS_EAGER = True +CELERY_TASK_SERIALIZER = 'json' +CELERY_ACCEPT_CONTENT = ['json'] +CELERY_RESULT_SERIALIZER = 'json' + SESSION_COOKIE_DOMAIN = config.get('c3nav', 'cookie_domain', fallback=None) SESSION_COOKIE_SECURE = config.getboolean('c3nav', 'session_cookie_secure', fallback=False) diff --git a/src/requirements/production.txt b/src/requirements/production.txt index 82814034..ac516268 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -5,3 +5,4 @@ csscompressor djangorestframework>=3.4,<3.5 django-filter>=0.14,<0.15 shapely>=1.5,<1.6 +celery>=3.1,<3.2