Explorar o código

MongoDB: Pickle url with backend. Closes #2347

Conflicts:
	celery/backends/mongodb.py
Ask Solem %!s(int64=10) %!d(string=hai) anos
pai
achega
ee1366ab54
Modificáronse 1 ficheiros con 8 adicións e 8 borrados
  1. 8 8
      celery/backends/mongodb.py

+ 8 - 8
celery/backends/mongodb.py

@@ -56,7 +56,7 @@ class MongoBackend(BaseBackend):
 
     _connection = None
 
-    def __init__(self, *args, **kwargs):
+    def __init__(self, app=None, url=None, **kwargs):
         """Initialize MongoDB backend instance.
 
         :raises celery.exceptions.ImproperlyConfigured: if
@@ -64,7 +64,7 @@ class MongoBackend(BaseBackend):
 
         """
         self.options = {}
-        super(MongoBackend, self).__init__(*args, **kwargs)
+        super(MongoBackend, self).__init__(app, **kwargs)
         self.expires = kwargs.get('expires') or maybe_timedelta(
             self.app.conf.CELERY_TASK_RESULT_EXPIRES)
 
@@ -95,10 +95,10 @@ class MongoBackend(BaseBackend):
             self.options.setdefault('max_pool_size', self.max_pool_size)
             self.options.setdefault('auto_start_request', False)
 
-        url = kwargs.get('url')
-        if url:
+        self.url = url
+        if self.url:
             # Specifying backend as an URL
-            self.host = url
+            self.host = self.url
 
     def _get_connection(self):
         """Connect to the MongoDB server."""
@@ -210,9 +210,9 @@ class MongoBackend(BaseBackend):
         )
 
     def __reduce__(self, args=(), kwargs={}):
-        kwargs.update(
-            dict(expires=self.expires))
-        return super(MongoBackend, self).__reduce__(args, kwargs)
+        return super(MongoBackend, self).__reduce__(
+            args, dict(kwargs, expires=self.expires, url=self.url),
+        )
 
     def _get_database(self):
         conn = self._get_connection()