Explorar o código

Default Loader: Set default backend to AMQP if not configured

Ask Solem %!s(int64=15) %!d(string=hai) anos
pai
achega
26a3aea320
Modificáronse 2 ficheiros con 9 adicións e 1 borrados
  1. 4 0
      celery/backends/amqp.py
  2. 5 1
      celery/loaders/default.py

+ 4 - 0
celery/backends/amqp.py

@@ -52,6 +52,10 @@ class AMQPBackend(BaseDictBackend):
     serializer = conf.RESULT_SERIALIZER
     _connection = None
 
+    def __init__(self, *args, **kwargs):
+        self._connection = kwargs.get("connection", None)
+        super(AMQPBackend, self).__init__(*args, **kwargs)
+
     def _create_publisher(self, task_id, connection):
         delivery_mode = self.persistent and 2 or 1
 

+ 5 - 1
celery/loaders/default.py

@@ -15,6 +15,10 @@ DEFAULT_SETTINGS = {
     "CELERY_IMPORTS": (),
 }
 
+DEFAULT_UNCONFIGURED_SETTINGS = {
+    "CELERY_RESULT_BACKEND": "amqp",
+}
+
 
 class NotConfigured(UserWarning):
     """Celery has not been configured, as no config module has been found."""
@@ -62,7 +66,7 @@ class Loader(BaseLoader):
             warnings.warn("No celeryconfig.py module found! Please make "
                           "sure it exists and is available to Python.",
                           NotConfigured)
-            return self.setup_settings({})
+            return self.setup_settings(DEFAULT_UNCONFIGURED_SETTINGS)
         else:
             usercfg = dict((key, getattr(celeryconfig, key))
                             for key in dir(celeryconfig)