Browse Source

Adds CASSANDRA settings to app/defaults

Ask Solem 13 years ago
parent
commit
ca91fdb2b1
2 changed files with 25 additions and 18 deletions
  1. 8 0
      celery/app/defaults.py
  2. 17 18
      celery/backends/cassandra.py

+ 8 - 0
celery/app/defaults.py

@@ -82,6 +82,14 @@ NAMESPACES = {
         "TRANSPORT": Option(None, type="string"),
         "TRANSPORT_OPTIONS": Option({}, type="dict"),
     },
+    "CASSANDRA": {
+        "COLUMN_FAMILY": Option(None, type="string"),
+        "DETAILED_MODE": Option(False, type="bool"),
+        "KEYSPACE": Option(None, type="string"),
+        "READ_CONSISTENCY": Option(None, type="string"),
+        "SERVERS": Option(None, type="list"),
+        "WRITE_CONSISTENCY": Option(None, type="string"),
+    },
     "CELERY": {
         "ACKS_LATE": Option(False, type="bool"),
         "ALWAYS_EAGER": Option(False, type="bool"),

+ 17 - 18
celery/backends/cassandra.py

@@ -57,24 +57,23 @@ class CassandraBackend(BaseDictBackend):
                 "You need to install the pycassa library to use the "
                 "Cassandra backend. See https://github.com/pycassa/pycassa")
 
-        self.servers = servers or \
-                        self.app.conf.get("CASSANDRA_SERVERS", self.servers)
-        self.keyspace = keyspace or \
-                            self.app.conf.get("CASSANDRA_KEYSPACE",
-                                              self.keyspace)
-        self.column_family = column_family or \
-                                self.app.conf.get("CASSANDRA_COLUMN_FAMILY",
-                                                  self.column_family)
-        self.cassandra_options = dict(cassandra_options or {},
-                                   **self.app.conf.get("CASSANDRA_OPTIONS",
-                                                       {}))
-        self.detailed_mode = detailed_mode or \
-                                self.app.conf.get("CASSANDRA_DETAILED_MODE",
-                                                  self.detailed_mode)
-        read_cons = self.app.conf.get("CASSANDRA_READ_CONSISTENCY",
-                                      "LOCAL_QUORUM")
-        write_cons = self.app.conf.get("CASSANDRA_WRITE_CONSISTENCY",
-                                       "LOCAL_QUORUM")
+        conf = self.app.conf
+        self.servers = (servers or
+                        conf.get("CASSANDRA_SERVERS") or
+                        self.servers)
+        self.keyspace = (keyspace or
+                         conf.get("CASSANDRA_KEYSPACE") or
+                         self.keyspace)
+        self.column_family = (column_family or
+                              conf.get("CASSANDRA_COLUMN_FAMILY") or
+                              self.column_family)
+        self.cassandra_options = dict(conf.get("CASSANDRA_OPTIONS") or {},
+                                      **cassandra_options or {})
+        self.detailed_mode = (detailed_mode or
+                              conf.get("CASSANDRA_DETAILED_MODE") or
+                              self.detailed_mode)
+        read_cons = conf.get("CASSANDRA_READ_CONSISTENCY") or "LOCAL_QUORUM"
+        write_cons = conf.get("CASSANDRA_WRITE_CONSISTENCY") or "LOCAL_QUORUM"
         try:
             self.read_consistency = getattr(pycassa.ConsistencyLevel,
                                             read_cons)