瀏覽代碼

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 15 年之前
父節點
當前提交
c69e7be7c1
共有 1 個文件被更改,包括 6 次插入8 次删除
  1. 6 8
      celery/loaders/default.py

+ 6 - 8
celery/loaders/default.py

@@ -17,21 +17,19 @@ class Loader(BaseLoader):
 
 
     def read_configuration(self):
     def read_configuration(self):
         config = dict(DEFAULT_SETTINGS)
         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)
                             for key in dir(celeryconfig)
                                 if wanted_module_item(key))
                                 if wanted_module_item(key))
         config.update(usercfg)
         config.update(usercfg)
         from django.conf import settings
         from django.conf import settings
         if not settings.configured:
         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
         return settings
 
 
     def on_worker_init(self):
     def on_worker_init(self):
-        imports = getattr(self.conf, "CELERY_TASK_MODULES", [])
+        imports = getattr(self.conf, "CELERY_IMPORTS", [])
         for module in imports:
         for module in imports:
             __import__(module, [], [], [''])
             __import__(module, [], [], [''])