瀏覽代碼

Add possibility to set celeryconfig module with ENV["CELERY_CONFIG_MODULE"] + always add celery to INSTALLED_APPS

Ask Solem 15 年之前
父節點
當前提交
a23774fe46
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      celery/loaders/default.py

+ 7 - 1
celery/loaders/default.py

@@ -1,5 +1,8 @@
+import os
 from celery.loaders.base import BaseLoader
 
+DEFAULT_CONFIG_MODULE = "celeryconfig"
+
 DEFAULT_SETTINGS = {
     "DEBUG": False,
     "DATABASE_ENGINE": "sqlite3",
@@ -21,9 +24,12 @@ class Loader(BaseLoader):
     """
 
     def read_configuration(self):
-        """Read configuration from ``celeryconf.py`` and configure
+        """Read configuration from ``celeryconfig.py`` and configure
         celery and Django so it can be used by regular Python."""
         config = dict(DEFAULT_SETTINGS)
+        configname = os.environ.get("CELERY_CONFIG_MODULE",
+                                    DEFAULT_CONFIG_MODULE)
+        celeryconfig = __import__(configname, {}, {}, [''])
         import celeryconfig
         usercfg = dict((key, getattr(celeryconfig, key))
                             for key in dir(celeryconfig)