|
@@ -1,3 +1,4 @@
|
|
|
|
+BUILTIN_MODULES = ["celery.task"]
|
|
|
|
|
|
|
|
|
|
class BaseLoader(object):
|
|
class BaseLoader(object):
|
|
@@ -17,6 +18,7 @@ class BaseLoader(object):
|
|
|
|
|
|
"""
|
|
"""
|
|
_conf_cache = None
|
|
_conf_cache = None
|
|
|
|
+ worker_initialized = False
|
|
|
|
|
|
def on_task_init(self, task_id, task):
|
|
def on_task_init(self, task_id, task):
|
|
"""This method is called before a task is executed."""
|
|
"""This method is called before a task is executed."""
|
|
@@ -31,8 +33,14 @@ class BaseLoader(object):
|
|
|
|
|
|
def import_default_modules(self):
|
|
def import_default_modules(self):
|
|
imports = getattr(self.conf, "CELERY_IMPORTS", None) or []
|
|
imports = getattr(self.conf, "CELERY_IMPORTS", None) or []
|
|
|
|
+ imports = set(list(imports) + BUILTIN_MODULES)
|
|
return map(self.import_task_module, imports)
|
|
return map(self.import_task_module, imports)
|
|
|
|
|
|
|
|
+ def init_worker(self):
|
|
|
|
+ if not self.worker_initialized:
|
|
|
|
+ self.worker_initialized = True
|
|
|
|
+ self.on_worker_init()
|
|
|
|
+
|
|
@property
|
|
@property
|
|
def conf(self):
|
|
def conf(self):
|
|
"""Loader configuration."""
|
|
"""Loader configuration."""
|