Parcourir la source

defaultloader: CELERY_IMPORTS is a setting for modules to be imported at worker init.
Also importing of celeryconfig now propogates ImportError, and modifies
django.conf.settings even if it's already configured by another app.

Ask Solem il y a 16 ans
Parent
commit
c69e7be7c1
1 fichiers modifiés avec 6 ajouts et 8 suppressions
  1. 6 8
      celery/loaders/default.py

+ 6 - 8
celery/loaders/default.py

@@ -17,21 +17,19 @@ class Loader(BaseLoader):
 
     def read_configuration(self):
         config = dict(DEFAULT_SETTINGS)
-        try:
-            import celeryconfig
-        except ImportError:
-            pass
-        else:
-            usercfg = dict((key, getattr(celeryconfig, key))
+        import celeryconfig
+        usercfg = dict((key, getattr(celeryconfig, key))
                             for key in dir(celeryconfig)
                                 if wanted_module_item(key))
         config.update(usercfg)
         from django.conf import settings
         if not settings.configured:
-            settings.configure(**config)
+            settings.configure()
+        for config_key, config_value in usercfg.items():
+            setattr(settings, config_key, config_value)
         return settings
 
     def on_worker_init(self):
-        imports = getattr(self.conf, "CELERY_TASK_MODULES", [])
+        imports = getattr(self.conf, "CELERY_IMPORTS", [])
         for module in imports:
             __import__(module, [], [], [''])