Browse Source

MongoDB: MONGODB_BACKEND_SETTINGS now accepts "options" for kwargs to pass to pymongo.Connection. Closes #1015

Ask Solem 12 năm trước cách đây
mục cha
commit
6eca044914
2 tập tin đã thay đổi với 10 bổ sung1 xóa
  1. 4 1
      celery/backends/mongodb.py
  2. 6 0
      docs/configuration.rst

+ 4 - 1
celery/backends/mongodb.py

@@ -73,6 +73,7 @@ class MongoBackend(BaseBackend):
             self.mongodb_host = config.get('host', self.mongodb_host)
             self.mongodb_port = int(config.get('port', self.mongodb_port))
             self.mongodb_user = config.get('user', self.mongodb_user)
+            self.mongodb_options = config.get('options', {})
             self.mongodb_password = config.get(
                 'password', self.mongodb_password)
             self.mongodb_database = config.get(
@@ -104,7 +105,9 @@ class MongoBackend(BaseBackend):
                     and not self.mongodb_host.startswith('mongodb://'):
                 args.append(self.mongodb_port)
 
-            self._connection = Connection(*args, **kwargs)
+            self._connection = Connection(
+                *args, **dict(kwargs, self.mongodb_options)
+            )
 
         return self._connection
 

+ 6 - 0
docs/configuration.rst

@@ -485,6 +485,12 @@ This is a dict supporting the following keys:
     than max_pool_size, sockets will be closed when they are released.
     Defaults to 10.
 
+* options
+
+    Additional keyword arguments to pass to the mongodb connection
+    constructor.  See the :mod:`pymongo` docs to see a list of arguments
+    supported.
+
 .. _example-mongodb-result-config:
 
 Example configuration