From d8592fc6d8d3e1c3efba54dfe478a1f0d582b917 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 6 Aug 2017 12:30:56 +0530 Subject: [PATCH] Added celery files --- dynamicweb/__init__.py | 5 +++++ dynamicweb/celery.py | 22 ++++++++++++++++++++++ dynamicweb/settings/base.py | 9 +++++++++ requirements.txt | 2 ++ 4 files changed, 38 insertions(+) create mode 100644 dynamicweb/celery.py diff --git a/dynamicweb/__init__.py b/dynamicweb/__init__.py index e69de29b..b64e43e8 100644 --- a/dynamicweb/__init__.py +++ b/dynamicweb/__init__.py @@ -0,0 +1,5 @@ +from __future__ import absolute_import + +# This will make sure the app is always imported when +# Django starts so that shared_task will use this app. +from .celery import app as celery_app diff --git a/dynamicweb/celery.py b/dynamicweb/celery.py new file mode 100644 index 00000000..749ffdef --- /dev/null +++ b/dynamicweb/celery.py @@ -0,0 +1,22 @@ +from __future__ import absolute_import, unicode_literals +import os +from celery import Celery + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dynamicweb.settings') + +app = Celery('dynamicweb') + +# Using a string here means the worker don't have to serialize +# the configuration object to child processes. +# - namespace='CELERY' means all celery-related configuration keys +# should have a `CELERY_` prefix. +app.config_from_object('django.conf:settings', namespace='CELERY') + +# Load task modules from all registered Django app configs. +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + + +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 40187f84..f4c4b68d 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -521,6 +521,15 @@ GOOGLE_ANALYTICS_PROPERTY_IDS = { 'dynamicweb-staging.ungleich.ch': 'staging' } +# CELERY Settings +#BROKER_URL = 'redis://localhost:6379' +BROKER_URL = 'redis+socket:///var/run/redis/redis.sock' +CELERY_RESULT_BACKEND = 'redis://localhost:6379' +CELERY_ACCEPT_CONTENT = ['application/json'] +CELERY_TASK_SERIALIZER = 'json' +CELERY_RESULT_SERIALIZER = 'json' +CELERY_TIMEZONE = 'Europe/Zurich' + ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING') if ENABLE_DEBUG_LOGGING: diff --git a/requirements.txt b/requirements.txt index f392f4d9..2520d617 100644 --- a/requirements.txt +++ b/requirements.txt @@ -86,3 +86,5 @@ git+https://github.com/ungleich/python-oca.git#egg=python-oca djangorestframework flake8==3.3.0 python-memcached==1.58 +celery==4.0.2 +redis==2.10.5