Browse Source

Adds new option CELERY_INCLUDE as an alternative to CELERY_IMPORTS. Also Celery(include=[..]) works

Ask Solem 13 years ago
parent
commit
12a00a2513
4 changed files with 8 additions and 4 deletions
  1. 3 1
      celery/app/base.py
  2. 1 0
      celery/app/defaults.py
  3. 2 2
      celery/apps/worker.py
  4. 2 1
      celery/loaders/base.py

+ 3 - 1
celery/app/base.py

@@ -62,7 +62,7 @@ class Celery(object):
     def __init__(self, main=None, loader=None, backend=None,
             amqp=None, events=None, log=None, control=None,
             set_as_current=True, accept_magic_kwargs=False,
-            tasks=None, broker=None, **kwargs):
+            tasks=None, broker=None, include=None, **kwargs):
         self.clock = LamportClock()
         self.main = main
         self.amqp_cls = amqp or self.amqp_cls
@@ -86,6 +86,8 @@ class Celery(object):
         self._preconf = {}
         if broker:
             self._preconf["BROKER_URL"] = broker
+        if include:
+            self._preconf["CELERY_IMPORTS"] = include
 
         if self.set_as_current:
             self.set_current()

+ 1 - 0
celery/app/defaults.py

@@ -117,6 +117,7 @@ NAMESPACES = {
         "ENABLE_UTC": Option(False, type="bool"),
         "EVENT_SERIALIZER": Option("json"),
         "IMPORTS": Option((), type="tuple"),
+        "INCLUDE": Option((), type="tuple"),
         "IGNORE_RESULT": Option(False, type="bool"),
         "MAX_CACHED_RESULTS": Option(5000, type="int"),
         "MESSAGE_COMPRESSION": Option(None, type="string"),

+ 2 - 2
celery/apps/worker.py

@@ -106,8 +106,8 @@ class Worker(configurated):
         if self.include:
             if isinstance(self.include, basestring):
                 self.include = self.include.split(",")
-            app.conf.CELERY_IMPORTS = tuple(
-                    self.include) + tuple(app.conf.CELERY_IMPORTS)
+            app.conf.CELERY_INCLUDE = (
+                tuple(app.conf.CELERY_INCLUDE) + tuple(self.include))
         self.loglevel = mlevel(self.loglevel)
 
     def run(self):

+ 2 - 1
celery/loaders/base.py

@@ -101,7 +101,8 @@ class BaseLoader(object):
     def import_default_modules(self):
         return [self.import_task_module(m)
             for m in set(maybe_list(self.app.conf.CELERY_IMPORTS))
-                        | self.builtin_modules]
+                   | set(maybe_list(self.app.conf.CELERY_INCLUDE))
+                   | self.builtin_modules]
 
     def init_worker(self):
         if not self.worker_initialized: