diff --git a/billard/tasks.py b/billard/tasks.py new file mode 100644 index 0000000..fded6ad --- /dev/null +++ b/billard/tasks.py @@ -0,0 +1,8 @@ +from __future__ import absolute_import, unicode_literals +from celery import shared_task +from . import models + + +@shared_task +def add(x, y): + return x + y diff --git a/caromserver/__init__.py b/caromserver/__init__.py index e69de29..3b91b07 100644 --- a/caromserver/__init__.py +++ b/caromserver/__init__.py @@ -0,0 +1,7 @@ +from __future__ import absolute_import, unicode_literals + +# 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 + +__all__ = ['celery_app'] diff --git a/caromserver/celery.py b/caromserver/celery.py new file mode 100644 index 0000000..8914e86 --- /dev/null +++ b/caromserver/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', 'caromserver.settings') + +app = Celery('caromserver') + +# 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') + +# Load task modules from all registered Django app configs. +#app.autodiscover_tasks() + + +@app.task(bind=True) +def debug_task(self): + print('Request: {0!r}'.format(self.request)) \ No newline at end of file diff --git a/caromserver/settings.py b/caromserver/settings.py index fe18ef8..df5161a 100644 --- a/caromserver/settings.py +++ b/caromserver/settings.py @@ -138,6 +138,15 @@ LOGOUT_URL = 'logout' LOGIN_REDIRECT_URL = 'carom_index' LOGOUT_REDIRECT_URL = 'carom_index' +# CELERY STUFF +BROKER_URL = 'redis://localhost:6379' +CELERY_RESULT_BACKEND = 'redis://localhost:6379' +CELERY_ACCEPT_CONTENT = ['application/json'] +CELERY_TASK_SERIALIZER = 'json' +CELERY_RESULT_SERIALIZER = 'json' +CELERY_TIMEZONE = 'Europe/Berlin' + + STATIC_ROOT = "/srv/carom/carom-server/static/" try: