From c941cdaf067c9ed6b26edca4503525c1ecf63a49 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 26 Nov 2013 12:57:33 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20#46=20=E2=80=94=20Update=20cookbook=20w?= =?UTF-8?q?ith=20an=20example=20for=20Celery=20>=3D=203.1.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/cookbook.rst | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/cookbook.rst b/docs/cookbook.rst index d6e7b28..df50e65 100644 --- a/docs/cookbook.rst +++ b/docs/cookbook.rst @@ -86,6 +86,9 @@ See the repository of the template for more information: Celery ------ +< 3.1 +^^^^^ + Given Celery's way to load Django settings in worker processes you should probably just add the following to the **beginning** of your settings module:: @@ -94,6 +97,44 @@ probably just add the following to the **beginning** of your settings module:: That has the same effect as using the ``manage.py`` or ``wsgi.py`` utilities. +>= 3.1 +^^^^^^ + +In Celery 3.1 and later the integration between Django and Celery has been +simplified to use the standard Celery Python API. Django projects using Celery +are now advised to add a ``celery.py`` file that instantiates an explicit +``Celery`` client app. + +Here's how to integrate django-configurations following the `example from +Celery's documentation`_: + +.. code-block:: python + :emphasize-lines: 9, 11-12 + + from __future__ import absolute_import + + import os + + from celery import Celery + from django.conf import settings + + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + os.environ.setdefault('DJANGO_CONFIGURATION', 'MySiteConfiguration') + + from configurations import importer + importer.install() + + app = Celery('mysite') + app.config_from_object('django.conf:settings') + app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) + + @app.task(bind=True) + def debug_task(self): + print('Request: {0!r}'.format(self.request)) + +.. _`example from Celery's documentation`: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html + + iPython notebooks ----------------- @@ -143,7 +184,6 @@ sure to use something like the following script:: #!/usr/bin/env python import os - import sys os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') os.environ.setdefault('DJANGO_CONFIGURATION', 'MySiteConfiguration')