|
@@ -39,6 +39,7 @@ from celery.utils import abstract
|
|
from celery.utils import gen_task_name
|
|
from celery.utils import gen_task_name
|
|
from celery.utils.dispatch import Signal
|
|
from celery.utils.dispatch import Signal
|
|
from celery.utils.functional import first, maybe_list, head_from_fun
|
|
from celery.utils.functional import first, maybe_list, head_from_fun
|
|
|
|
+from celery.utils.timeutils import timezone
|
|
from celery.utils.imports import instantiate, symbol_by_name
|
|
from celery.utils.imports import instantiate, symbol_by_name
|
|
from celery.utils.log import get_logger
|
|
from celery.utils.log import get_logger
|
|
from celery.utils.objects import FallbackContext, mro_lookup
|
|
from celery.utils.objects import FallbackContext, mro_lookup
|
|
@@ -58,7 +59,7 @@ __all__ = ['Celery']
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
-_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
|
|
|
|
|
|
+USING_EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
|
|
BUILTIN_FIXUPS = {
|
|
BUILTIN_FIXUPS = {
|
|
'celery.fixups.django:fixup',
|
|
'celery.fixups.django:fixup',
|
|
}
|
|
}
|
|
@@ -89,6 +90,7 @@ def _after_fork_cleanup_app(app):
|
|
|
|
|
|
|
|
|
|
class PendingConfiguration(UserDict, AttributeDictMixin):
|
|
class PendingConfiguration(UserDict, AttributeDictMixin):
|
|
|
|
+
|
|
callback = None
|
|
callback = None
|
|
data = None
|
|
data = None
|
|
|
|
|
|
@@ -104,7 +106,8 @@ class Celery(object):
|
|
"""Celery application.
|
|
"""Celery application.
|
|
|
|
|
|
:param main: Name of the main module if running as `__main__`.
|
|
:param main: Name of the main module if running as `__main__`.
|
|
- This is used as a prefix for task names.
|
|
|
|
|
|
+ This is used as the prefix for autogenerated task names.
|
|
|
|
+
|
|
:keyword broker: URL of the default broker used.
|
|
:keyword broker: URL of the default broker used.
|
|
:keyword loader: The loader class, or the name of the loader class to use.
|
|
:keyword loader: The loader class, or the name of the loader class to use.
|
|
Default is :class:`celery.loaders.app.AppLoader`.
|
|
Default is :class:`celery.loaders.app.AppLoader`.
|
|
@@ -145,6 +148,8 @@ class Celery(object):
|
|
#: See :ref:`extending-bootsteps`.
|
|
#: See :ref:`extending-bootsteps`.
|
|
steps = None
|
|
steps = None
|
|
|
|
|
|
|
|
+ builtin_fixups = BUILTIN_FIXUPS
|
|
|
|
+
|
|
amqp_cls = 'celery.app.amqp:AMQP'
|
|
amqp_cls = 'celery.app.amqp:AMQP'
|
|
backend_cls = None
|
|
backend_cls = None
|
|
events_cls = 'celery.events:Events'
|
|
events_cls = 'celery.events:Events'
|
|
@@ -153,10 +158,10 @@ class Celery(object):
|
|
control_cls = 'celery.app.control:Control'
|
|
control_cls = 'celery.app.control:Control'
|
|
task_cls = 'celery.app.task:Task'
|
|
task_cls = 'celery.app.task:Task'
|
|
registry_cls = TaskRegistry
|
|
registry_cls = TaskRegistry
|
|
|
|
+
|
|
_fixups = None
|
|
_fixups = None
|
|
_pool = None
|
|
_pool = None
|
|
_conf = None
|
|
_conf = None
|
|
- builtin_fixups = BUILTIN_FIXUPS
|
|
|
|
_after_fork_registered = False
|
|
_after_fork_registered = False
|
|
|
|
|
|
#: Signal sent when app is loading configuration.
|
|
#: Signal sent when app is loading configuration.
|
|
@@ -240,6 +245,10 @@ class Celery(object):
|
|
self.on_init()
|
|
self.on_init()
|
|
_register_app(self)
|
|
_register_app(self)
|
|
|
|
|
|
|
|
+ def on_init(self):
|
|
|
|
+ """Optional callback called at init."""
|
|
|
|
+ pass
|
|
|
|
+
|
|
def __autoset(self, key, value):
|
|
def __autoset(self, key, value):
|
|
if value:
|
|
if value:
|
|
self._preconf[key] = value
|
|
self._preconf[key] = value
|
|
@@ -278,10 +287,6 @@ class Celery(object):
|
|
self._pool = None
|
|
self._pool = None
|
|
_deregister_app(self)
|
|
_deregister_app(self)
|
|
|
|
|
|
- def on_init(self):
|
|
|
|
- """Optional callback called at init."""
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
def start(self, argv=None):
|
|
def start(self, argv=None):
|
|
"""Run :program:`celery` using `argv`.
|
|
"""Run :program:`celery` using `argv`.
|
|
|
|
|
|
@@ -289,8 +294,8 @@ class Celery(object):
|
|
|
|
|
|
"""
|
|
"""
|
|
return instantiate(
|
|
return instantiate(
|
|
- 'celery.bin.celery:CeleryCommand',
|
|
|
|
- app=self).execute_from_commandline(argv)
|
|
|
|
|
|
+ 'celery.bin.celery:CeleryCommand', app=self
|
|
|
|
+ ).execute_from_commandline(argv)
|
|
|
|
|
|
def worker_main(self, argv=None):
|
|
def worker_main(self, argv=None):
|
|
"""Run :program:`celery worker` using `argv`.
|
|
"""Run :program:`celery worker` using `argv`.
|
|
@@ -299,8 +304,8 @@ class Celery(object):
|
|
|
|
|
|
"""
|
|
"""
|
|
return instantiate(
|
|
return instantiate(
|
|
- 'celery.bin.worker:worker',
|
|
|
|
- app=self).execute_from_commandline(argv)
|
|
|
|
|
|
+ 'celery.bin.worker:worker', app=self
|
|
|
|
+ ).execute_from_commandline(argv)
|
|
|
|
|
|
def task(self, *args, **opts):
|
|
def task(self, *args, **opts):
|
|
"""Decorator to create a task class out of any callable.
|
|
"""Decorator to create a task class out of any callable.
|
|
@@ -332,7 +337,7 @@ class Celery(object):
|
|
application is fully set up (finalized).
|
|
application is fully set up (finalized).
|
|
|
|
|
|
"""
|
|
"""
|
|
- if _EXECV and opts.get('lazy', True):
|
|
|
|
|
|
+ if USING_EXECV and opts.get('lazy', True):
|
|
# When using execv the task in the original module will point to a
|
|
# When using execv the task in the original module will point to a
|
|
# different app, so doing things like 'add.request' will point to
|
|
# different app, so doing things like 'add.request' will point to
|
|
# a different task instance. This makes sure it will always use
|
|
# a different task instance. This makes sure it will always use
|
|
@@ -1127,7 +1132,6 @@ class Celery(object):
|
|
:setting:`timezone` setting.
|
|
:setting:`timezone` setting.
|
|
|
|
|
|
"""
|
|
"""
|
|
- from celery.utils.timeutils import timezone
|
|
|
|
conf = self.conf
|
|
conf = self.conf
|
|
tz = conf.timezone
|
|
tz = conf.timezone
|
|
if not tz:
|
|
if not tz:
|