Przeglądaj źródła

BROKER_TRANSPORT is now preferred over BROKER_BACKEND

Ask Solem 14 lat temu
rodzic
commit
d328ac4e44

+ 26 - 14
celery/app/base.py

@@ -20,8 +20,8 @@ from threading import Lock
 
 from kombu.utils import cached_property
 
+from celery import datastructures
 from celery.app.defaults import DEFAULTS
-from celery.datastructures import ConfigurationView
 from celery.utils import instantiate, lpmerge
 
 import kombu
@@ -99,6 +99,26 @@ class LamportClock(object):
         return self.value
 
 
+class Settings(datastructures.ConfigurationView):
+
+    @property
+    def CELERY_RESULT_BACKEND(self):
+        """Resolves deprecated alias ``CELERY_BACKEND``."""
+        return self.get("CELERY_RESULT_BACKEND") or self.get("CELERY_BACKEND")
+
+    @property
+    def BROKER_TRANSPORT(self):
+        """Resolves compat aliases ``BROKER_BACKEND`` and ``CARROT_BACKEND``."""
+        return (self.get("BROKER_TRANSPORT") or
+                self.get("BROKER_BACKEND") or
+                self.get("CARROT_BACKEND"))
+
+    @property
+    def BROKER_BACKEND(self):
+        """Deprecated compat alias to :attr:`BROKER_TRANSPORT`."""
+        return self.BROKER_TRANSPORT
+
+
 class BaseApp(object):
     """Base class for apps."""
     SYSTEM = _platform.system()
@@ -229,7 +249,7 @@ class BaseApp(object):
         :keyword insist: defaults to the :setting:`BROKER_INSIST` setting.
         :keyword connect_timeout: defaults to the
             :setting:`BROKER_CONNECTION_TIMEOUT` setting.
-        :keyword backend_cls: defaults to the :setting:`BROKER_BACKEND`
+        :keyword backend_cls: defaults to the :setting:`BROKER_TRANSPORT`
             setting.
 
         :returns :class:`kombu.connection.BrokerConnection`:
@@ -241,7 +261,7 @@ class BaseApp(object):
                     password or self.conf.BROKER_PASSWORD,
                     virtual_host or self.conf.BROKER_VHOST,
                     port or self.conf.BROKER_PORT,
-                    transport=transport or self.conf.BROKER_BACKEND,
+                    transport=transport or self.conf.BROKER_TRANSPORT,
                     insist=self.either("BROKER_INSIST", insist),
                     ssl=self.either("BROKER_USE_SSL", ssl),
                     connect_timeout=self.either(
@@ -281,14 +301,6 @@ class BaseApp(object):
 
     def prepare_config(self, c):
         """Prepare configuration before it is merged with the defaults."""
-        if not c.get("CELERY_RESULT_BACKEND"):
-            rbackend = c.get("CELERY_BACKEND")
-            if rbackend:
-                c["CELERY_RESULT_BACKEND"] = rbackend
-        if not c.get("BROKER_BACKEND"):
-            cbackend = c.get("BROKER_TRANSPORT") or c.get("CARROT_BACKEND")
-            if cbackend:
-                c["BROKER_BACKEND"] = cbackend
         return c
 
     def mail_admins(self, subject, body, fail_silently=False):
@@ -323,8 +335,8 @@ class BaseApp(object):
         return backend_cls(app=self)
 
     def _get_config(self):
-        return ConfigurationView({},
-                [self.prepare_config(self.loader.conf), deepcopy(DEFAULTS)])
+        return Settings({}, [self.prepare_config(self.loader.conf),
+                             deepcopy(DEFAULTS)])
 
     def _after_fork(self, obj_):
         if self._pool:
@@ -340,7 +352,7 @@ class BaseApp(object):
                                  "celery_v": celery.__version__,
                                  "kombu_v": kombu.__version__,
                                  "py_v": _platform.python_version(),
-                                 "transport": self.conf.BROKER_BACKEND,
+                                 "transport": self.conf.BROKER_TRANSPORT,
                                  "results": self.conf.CELERY_RESULT_BACKEND}
 
     @property

+ 1 - 1
celery/conf.py

@@ -66,7 +66,7 @@ BROKER_INSIST = conf.BROKER_INSIST
 BROKER_CONNECTION_TIMEOUT = conf.BROKER_CONNECTION_TIMEOUT
 BROKER_CONNECTION_RETRY = conf.BROKER_CONNECTION_RETRY
 BROKER_CONNECTION_MAX_RETRIES = conf.BROKER_CONNECTION_MAX_RETRIES
-BROKER_BACKEND = conf.BROKER_BACKEND
+BROKER_BACKEND = conf.BROKER_TRANSPORT
 DEFAULT_QUEUE = conf.CELERY_DEFAULT_QUEUE
 DEFAULT_ROUTING_KEY = conf.CELERY_DEFAULT_ROUTING_KEY
 DEFAULT_EXCHANGE = conf.CELERY_DEFAULT_EXCHANGE

+ 1 - 1
celery/tests/config.py

@@ -1,6 +1,6 @@
 import os
 
-BROKER_BACKEND = "memory"
+BROKER_TRANSPORT = "memory"
 
 #: Don't want log output when running suite.
 CELERYD_HIJACK_ROOT_LOGGER = False

+ 1 - 1
celery/tests/test_app/test_app.py

@@ -135,7 +135,7 @@ class test_App(unittest.TestCase):
 
     def test_compat_setting_CARROT_BACKEND(self):
         self.app.config_from_object(Object(CARROT_BACKEND="set_by_us"))
-        self.assertEqual(self.app.conf.BROKER_BACKEND, "set_by_us")
+        self.assertEqual(self.app.conf.BROKER_TRANSPORT, "set_by_us")
 
     def test_mail_admins(self):
 

+ 5 - 5
docs/conf.py

@@ -21,11 +21,11 @@ import celery
 # use app loader
 from celery import Celery
 app = Celery(set_as_current=True)
-app.conf.update(BROKER_BACKEND="memory",
-                   CELERY_RESULT_BACKEND="cache",
-                   CELERY_CACHE_BACKEND="memory",
-                   CELERYD_HIJACK_ROOT_LOGGER=False,
-                   CELERYD_LOG_COLOR=False)
+app.conf.update(BROKER_TRANSPORT="memory",
+                CELERY_RESULT_BACKEND="cache",
+                CELERY_CACHE_BACKEND="memory",
+                CELERYD_HIJACK_ROOT_LOGGER=False,
+                CELERYD_LOG_COLOR=False)
 
 # General configuration
 # ---------------------

+ 6 - 3
docs/configuration.rst

@@ -87,6 +87,7 @@ Task result backend settings
 
 CELERY_RESULT_BACKEND
 ~~~~~~~~~~~~~~~~~~~~~
+:Deprecated aliases: ``CELERY_BACKEND``
 
 The backend used to store task results (tombstones).
 Disabled by default.
@@ -525,10 +526,12 @@ persistent messages.
 Broker Settings
 ---------------
 
-.. setting:: BROKER_BACKEND
+.. setting:: BROKER_TRANSPORT
 
-BROKER_BACKEND
-~~~~~~~~~~~~~~
+BROKER_TRANSPORT
+~~~~~~~~~~~~~~~~
+:Aliases: ``BROKER_BACKEND``
+:Deprecated aliases: ``CARROT_BACKEND``
 
 The Kombu transport to use.  Default is ``amqplib``.
 

+ 3 - 3
docs/tutorials/otherqueues.rst

@@ -24,7 +24,7 @@ Configuration
 Configuration is easy, set the transport, and configure the location of
 your Redis database::
 
-    BROKER_BACKEND = "redis"
+    BROKER_TRANSPORT = "redis"
 
     BROKER_HOST = "localhost"  # Maps to redis host.
     BROKER_PORT = 6379         # Maps to redis port.
@@ -68,7 +68,7 @@ an SQLAlchemy database URI.
 
 #. Set your broker transport::
 
-    BROKER_BACKEND = "sqlakombu.transport.Transport"
+    BROKER_TRANSPORT = "sqlakombu.transport.Transport"
 
 #. Configure the database URI::
 
@@ -127,7 +127,7 @@ configuration values.
 
 #. Set your broker transport::
 
-    BROKER_BACKEND = "djkombu.transport.DatabaseTransport"
+    BROKER_TRANSPORT = "djkombu.transport.DatabaseTransport"
 
 #. Add :mod:`djkombu` to `INSTALLED_APPS`::
 

+ 2 - 1
funtests/suite/config.py

@@ -1,7 +1,8 @@
 import atexit
 import os
 
-BROKER_BACKEND = os.environ.get("BROKER_BACKEND") or "amqplib"
+BROKER_TRANSPORT = (os.environ.get("BROKER_TRANSPORT") or
+                    os.environ.get("BROKER_BACKEND") or "amqplib")
 
 BROKER_HOST = os.environ.get("BROKER_HOST") or "localhost"
 BROKER_USER = os.environ.get("BROKER_USER") or "guest"

+ 2 - 2
funtests/suite/test_leak.py

@@ -89,7 +89,7 @@ class test_leaks(LeakFunCase):
 
     def test_task_apply_leak(self):
         its = QUICKTEST and 10 or 1000
-        self.assertNotEqual(self.app.conf.BROKER_BACKEND, "memory")
+        self.assertNotEqual(self.app.conf.BROKER_TRANSPORT, "memory")
 
         @self.app.task
         def task1():
@@ -109,7 +109,7 @@ class test_leaks(LeakFunCase):
 
     def test_task_apply_leak_with_pool(self):
         its = QUICKTEST and 10 or 1000
-        self.assertNotEqual(self.app.conf.BROKER_BACKEND, "memory")
+        self.assertNotEqual(self.app.conf.BROKER_TRANSPORT, "memory")
 
         @self.app.task
         def task2():