From 7c84af700c226f8572f7690c0530a5da0f227fb9 Mon Sep 17 00:00:00 2001 From: Gust Date: Thu, 2 Jul 2015 10:56:04 -0300 Subject: [PATCH] Add celery to colab --- colab/__init__.py | 5 +++++ colab/celery.py | 27 +++++++++++++++++++++++++++ colab/settings.py | 2 ++ setup.py | 3 +++ vagrant/centos.sh | 4 ++++ 5 files changed, 41 insertions(+), 0 deletions(-) create mode 100644 colab/celery.py diff --git a/colab/__init__.py b/colab/__init__.py index e69de29..d13e951 100644 --- a/colab/__init__.py +++ b/colab/__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 # noqa diff --git a/colab/celery.py b/colab/celery.py new file mode 100644 index 0000000..5c6e1eb --- /dev/null +++ b/colab/celery.py @@ -0,0 +1,27 @@ +from __future__ import absolute_import + +import os + +from celery import Celery + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'colab.settings') + +from django.conf import settings + +app = Celery('colab') + +app.config_from_object('django.conf:settings') +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + +app.conf.update( + CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', +) +app.conf.update( + CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend', +) + + +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) diff --git a/colab/settings.py b/colab/settings.py index 12d3cc2..5997280 100644 --- a/colab/settings.py +++ b/colab/settings.py @@ -8,6 +8,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """ +BROKER_URL = 'amqp://guest:guest@localhost:5672/' # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(__file__) @@ -47,6 +48,7 @@ INSTALLED_APPS = ( 'hitcounter', 'i18n_model', 'taggit', + 'djcelery', # Own apps 'colab.home', diff --git a/setup.py b/setup.py index bf5b1b0..e60202b 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,9 @@ REQUIREMENTS = [ # Diazo 'diazo>=1.0.5', + # Celery + 'django-celery==3.1.16', + ### Move out of colab (as plugins): # Deps for badger diff --git a/vagrant/centos.sh b/vagrant/centos.sh index 2da5e5d..8c0098a 100755 --- a/vagrant/centos.sh +++ b/vagrant/centos.sh @@ -21,6 +21,10 @@ yum -y groupinstall "Development tools" yum install -y git unzip mercurial libev-devel gettext libxml2-devel libxslt-devel openssl-devel libffi-devel libjpeg-turbo-devel zlib-devel freetype-devel postgresql-devel python-devel postgresql-server java epel-release +### Install Rabbitmq +yum install -y rabbitmq-server +systemctl start rabbitmq-server + ### Install Virtualenvwrapper which pip2.7 > /dev/null || curl -s -L https://raw.githubusercontent.com/pypa/pip/1.5.6/contrib/get-pip.py | -- libgit2 0.21.2