Commits

Stefan Wehrmeyer committed 7990a5d

New Loader: load celery configuration from python module that is referenced by pylons config variable "celery_config" (defaults to celeryconfig module)

  • Participants
  • Parent commits 89f596f

Comments (0)

Files changed (1)

File celerypylons/loader.py

-from celery.loaders.base import BaseLoader
+from celery.loaders.default import Loader, wanted_module_item
 from pylons import config
-import types
 
-
-to_pylons = lambda x: x.replace('_','.').lower()
-to_celery = lambda x: x.replace('.', '_').upper()
-
-LIST_PARAMS = """CELERY_IMPORTS ADMINS ROUTES""".split()
-
-
-class PylonsSettingsProxy(object):
-    """Pylons Settings Proxy
-
-    Proxies settings from pylons.config
-    """
-    def __getattr__(self, key):
-        pylons_key = to_pylons(key)
-        try:
-            value = config[pylons_key]
-            if key in LIST_PARAMS:
-                return value.split()
-            return value
-        except KeyError:
-            raise AttributeError(pylons_key)
-
-    def __setattr__(self, key, value):
-        pylons_key = to_pylons(key)
-        config[pylons_key] = value
-
-
-class PylonsLoader(BaseLoader):
+class PylonsLoader(Loader):
     """Pylons celery loader
 
     Maps the celery config onto pylons.config
     """
     def read_configuration(self):
+        celeryconfig = self.import_module(config.get("celery_config", "celeryconfig"))
+        usercfg = dict((key, getattr(celeryconfig, key))
+                        for key in dir(celeryconfig)
+                            if wanted_module_item(key))
         self.configured = True
-        return PylonsSettingsProxy()
-
-    def on_worker_init(self):
-        """
-        Import task modules.
-        """
-        self.import_default_modules()
+        return self.setup_settings(usercfg)