From e76cfa15af8a156b9851236eebb74c22858db481 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 15 Mar 2019 14:32:47 +0100 Subject: Celery configuration --- example_project/__init__.py | 11 ----------- example_project/__init__.py.base.sample | 11 +++++++++++ example_project/__init__.py.celery.sample | 15 +++++++++++++++ example_project/celery.py.sample | 18 ++++++++++++++++++ example_project/settings.py | 4 ++-- 5 files changed, 46 insertions(+), 13 deletions(-) delete mode 100644 example_project/__init__.py create mode 100644 example_project/__init__.py.base.sample create mode 100644 example_project/__init__.py.celery.sample create mode 100644 example_project/celery.py.sample (limited to 'example_project') diff --git a/example_project/__init__.py b/example_project/__init__.py deleted file mode 100644 index c6adb7559..000000000 --- a/example_project/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -# force the retranslation of generated strings and external module -from django.utils.translation import ugettext_lazy as _ - -_(u"username") -_(u"email address") -_(u"warehouse") -_(u"New warehouse") -_(u"warehouse") -_(u"New organization") -_(u"New person") -_(u"New author") diff --git a/example_project/__init__.py.base.sample b/example_project/__init__.py.base.sample new file mode 100644 index 000000000..c6adb7559 --- /dev/null +++ b/example_project/__init__.py.base.sample @@ -0,0 +1,11 @@ +# force the retranslation of generated strings and external module +from django.utils.translation import ugettext_lazy as _ + +_(u"username") +_(u"email address") +_(u"warehouse") +_(u"New warehouse") +_(u"warehouse") +_(u"New organization") +_(u"New person") +_(u"New author") diff --git a/example_project/__init__.py.celery.sample b/example_project/__init__.py.celery.sample new file mode 100644 index 000000000..ebae6a3c3 --- /dev/null +++ b/example_project/__init__.py.celery.sample @@ -0,0 +1,15 @@ +# force the retranslation of generated strings and external module +from django.utils.translation import ugettext_lazy as _ + +from .celery import app as celery_app + +__all__ = ('celery_app',) + +_(u"username") +_(u"email address") +_(u"warehouse") +_(u"New warehouse") +_(u"warehouse") +_(u"New organization") +_(u"New person") +_(u"New author") diff --git a/example_project/celery.py.sample b/example_project/celery.py.sample new file mode 100644 index 000000000..3aed98038 --- /dev/null +++ b/example_project/celery.py.sample @@ -0,0 +1,18 @@ +import os +from celery import Celery + +# change example_project with your project name +project_name = "example_project" + +# set the default Django settings module for the 'celery' program. +os.environ.setdefault('DJANGO_SETTINGS_MODULE', project_name + '.settings') + +app = Celery(project_name) + +app.config_from_object('django.conf:settings', namespace='CELERY') +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/example_project/settings.py b/example_project/settings.py index 8a7343212..09590f807 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -273,7 +273,7 @@ DOT_BINARY = "" TEST_RUNNER = 'ishtar_common.tests.ManagedModelTestRunner' try: - from local_settings import * + from .local_settings import * except ImportError as e: print('Unable to load local_settings.py:', e) @@ -316,7 +316,7 @@ if DEBUG: LOGGING['loggers'][logger]['handlers'] += ['console'] if USE_BACKGROUND_TASK: - INSTALLED_APPS.append('background_task') + CELERY_BROKER_URL = 'amqp://localhost' if DJANGO_EXTENSIONS: INSTALLED_APPS.append('django_extensions') -- cgit v1.2.3