base.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.app.base
  4. ~~~~~~~~~~~~~~~
  5. Actual App instance implementation.
  6. """
  7. from __future__ import absolute_import
  8. import os
  9. import threading
  10. import warnings
  11. from collections import defaultdict, deque
  12. from contextlib import contextmanager
  13. from copy import deepcopy
  14. from operator import attrgetter
  15. from amqp import promise
  16. from billiard.util import register_after_fork
  17. from kombu.clocks import LamportClock
  18. from kombu.common import oid_from
  19. from kombu.utils import cached_property, uuid
  20. from celery import platforms
  21. from celery import signals
  22. from celery._state import (
  23. _task_stack, get_current_app, _set_current_app, set_default_app,
  24. _register_app, get_current_worker_task, connect_on_app_finalize,
  25. _announce_app_finalized,
  26. )
  27. from celery.exceptions import AlwaysEagerIgnored, ImproperlyConfigured
  28. from celery.five import items, values
  29. from celery.loaders import get_loader_cls
  30. from celery.local import PromiseProxy, maybe_evaluate
  31. from celery.utils.functional import first, maybe_list
  32. from celery.utils.imports import instantiate, symbol_by_name
  33. from celery.utils.objects import mro_lookup
  34. from .annotations import prepare as prepare_annotations
  35. from .defaults import DEFAULTS, find_deprecated_settings
  36. from .registry import TaskRegistry
  37. from .utils import (
  38. AppPickler, Settings, bugreport, _unpickle_app, _unpickle_app_v2, appstr,
  39. )
  40. __all__ = ['Celery']
  41. _EXECV = os.environ.get('FORKED_BY_MULTIPROCESSING')
  42. BUILTIN_FIXUPS = frozenset([
  43. 'celery.fixups.django:fixup',
  44. ])
  45. ERR_ENVVAR_NOT_SET = """\
  46. The environment variable {0!r} is not set,
  47. and as such the configuration could not be loaded.
  48. Please set this variable and make it point to
  49. a configuration module."""
  50. _after_fork_registered = False
  51. def app_has_custom(app, attr):
  52. return mro_lookup(app.__class__, attr, stop=(Celery, object),
  53. monkey_patched=[__name__])
  54. def _unpickle_appattr(reverse_name, args):
  55. """Given an attribute name and a list of args, gets
  56. the attribute from the current app and calls it."""
  57. return get_current_app()._rgetattr(reverse_name)(*args)
  58. def _global_after_fork():
  59. # Previously every app would call:
  60. # `register_after_fork(app, app._after_fork)`
  61. # but this created a leak as `register_after_fork` stores concrete object
  62. # references and once registered an object cannot be removed without
  63. # touching and iterating over the private afterfork registry list.
  64. #
  65. # See Issue #1949
  66. from celery import _state
  67. from multiprocessing.util import info
  68. for app in _state.apps:
  69. try:
  70. app._after_fork()
  71. except Exception as exc:
  72. info('after forker raised exception: %r' % (exc, ), exc_info=1)
  73. def _ensure_after_fork():
  74. global _after_fork_registered
  75. _after_fork_registered = True
  76. register_after_fork(_global_after_fork, _global_after_fork)
  77. class Celery(object):
  78. #: This is deprecated, use :meth:`reduce_keys` instead
  79. Pickler = AppPickler
  80. SYSTEM = platforms.SYSTEM
  81. IS_OSX, IS_WINDOWS = platforms.IS_OSX, platforms.IS_WINDOWS
  82. amqp_cls = 'celery.app.amqp:AMQP'
  83. backend_cls = None
  84. events_cls = 'celery.events:Events'
  85. loader_cls = 'celery.loaders.app:AppLoader'
  86. log_cls = 'celery.app.log:Logging'
  87. control_cls = 'celery.app.control:Control'
  88. task_cls = 'celery.app.task:Task'
  89. registry_cls = TaskRegistry
  90. _fixups = None
  91. _pool = None
  92. builtin_fixups = BUILTIN_FIXUPS
  93. def __init__(self, main=None, loader=None, backend=None,
  94. amqp=None, events=None, log=None, control=None,
  95. set_as_current=True, accept_magic_kwargs=False,
  96. tasks=None, broker=None, include=None, changes=None,
  97. config_source=None, fixups=None, task_cls=None,
  98. autofinalize=True, **kwargs):
  99. self.clock = LamportClock()
  100. self.main = main
  101. self.amqp_cls = amqp or self.amqp_cls
  102. self.backend_cls = backend or self.backend_cls
  103. self.events_cls = events or self.events_cls
  104. self.loader_cls = loader or self.loader_cls
  105. self.log_cls = log or self.log_cls
  106. self.control_cls = control or self.control_cls
  107. self.task_cls = task_cls or self.task_cls
  108. self.set_as_current = set_as_current
  109. self.registry_cls = symbol_by_name(self.registry_cls)
  110. self.accept_magic_kwargs = accept_magic_kwargs
  111. self.user_options = defaultdict(set)
  112. self.steps = defaultdict(set)
  113. self.autofinalize = autofinalize
  114. self.configured = False
  115. self._config_source = config_source
  116. self._pending_defaults = deque()
  117. self.finalized = False
  118. self._finalize_mutex = threading.Lock()
  119. self._pending = deque()
  120. self._tasks = tasks
  121. if not isinstance(self._tasks, TaskRegistry):
  122. self._tasks = TaskRegistry(self._tasks or {})
  123. # If the class defins a custom __reduce_args__ we need to use
  124. # the old way of pickling apps, which is pickling a list of
  125. # args instead of the new way that pickles a dict of keywords.
  126. self._using_v1_reduce = app_has_custom(self, '__reduce_args__')
  127. # these options are moved to the config to
  128. # simplify pickling of the app object.
  129. self._preconf = changes or {}
  130. if broker:
  131. self._preconf['BROKER_URL'] = broker
  132. if include:
  133. self._preconf['CELERY_IMPORTS'] = include
  134. # - Apply fixups.
  135. self.fixups = set(self.builtin_fixups) if fixups is None else fixups
  136. # ...store fixup instances in _fixups to keep weakrefs alive.
  137. self._fixups = [symbol_by_name(fixup)(self) for fixup in self.fixups]
  138. if self.set_as_current:
  139. self.set_current()
  140. self.on_init()
  141. _register_app(self)
  142. def set_current(self):
  143. _set_current_app(self)
  144. def set_default(self):
  145. set_default_app(self)
  146. def __enter__(self):
  147. return self
  148. def __exit__(self, *exc_info):
  149. self.close()
  150. def close(self):
  151. self._maybe_close_pool()
  152. def on_init(self):
  153. """Optional callback called at init."""
  154. pass
  155. def start(self, argv=None):
  156. return instantiate(
  157. 'celery.bin.celery:CeleryCommand',
  158. app=self).execute_from_commandline(argv)
  159. def worker_main(self, argv=None):
  160. return instantiate(
  161. 'celery.bin.worker:worker',
  162. app=self).execute_from_commandline(argv)
  163. def task(self, *args, **opts):
  164. """Creates new task class from any callable."""
  165. if _EXECV and not opts.get('_force_evaluate'):
  166. # When using execv the task in the original module will point to a
  167. # different app, so doing things like 'add.request' will point to
  168. # a differnt task instance. This makes sure it will always use
  169. # the task instance from the current app.
  170. # Really need a better solution for this :(
  171. from . import shared_task
  172. return shared_task(*args, _force_evaluate=True, **opts)
  173. def inner_create_task_cls(shared=True, filter=None, **opts):
  174. _filt = filter # stupid 2to3
  175. def _create_task_cls(fun):
  176. if shared:
  177. cons = lambda app: app._task_from_fun(fun, **opts)
  178. cons.__name__ = fun.__name__
  179. connect_on_app_finalize(cons)
  180. if self.accept_magic_kwargs: # compat mode
  181. task = self._task_from_fun(fun, **opts)
  182. if filter:
  183. task = filter(task)
  184. return task
  185. if self.finalized or opts.get('_force_evaluate'):
  186. ret = self._task_from_fun(fun, **opts)
  187. else:
  188. # return a proxy object that evaluates on first use
  189. ret = PromiseProxy(self._task_from_fun, (fun, ), opts,
  190. __doc__=fun.__doc__)
  191. self._pending.append(ret)
  192. if _filt:
  193. return _filt(ret)
  194. return ret
  195. return _create_task_cls
  196. if len(args) == 1:
  197. if callable(args[0]):
  198. return inner_create_task_cls(**opts)(*args)
  199. raise TypeError('argument 1 to @task() must be a callable')
  200. if args:
  201. raise TypeError(
  202. '@task() takes exactly 1 argument ({0} given)'.format(
  203. sum([len(args), len(opts)])))
  204. return inner_create_task_cls(**opts)
  205. def _task_from_fun(self, fun, **options):
  206. if not self.finalized and not self.autofinalize:
  207. raise RuntimeError('Contract breach: app not finalized')
  208. base = options.pop('base', None) or self.Task
  209. bind = options.pop('bind', False)
  210. T = type(fun.__name__, (base, ), dict({
  211. 'app': self,
  212. 'accept_magic_kwargs': False,
  213. 'run': fun if bind else staticmethod(fun),
  214. '_decorated': True,
  215. '__doc__': fun.__doc__,
  216. '__module__': fun.__module__,
  217. '__wrapped__': fun}, **options))()
  218. task = self._tasks[T.name] # return global instance.
  219. return task
  220. def finalize(self, auto=False):
  221. with self._finalize_mutex:
  222. if not self.finalized:
  223. if auto and not self.autofinalize:
  224. raise RuntimeError('Contract breach: app not finalized')
  225. self.finalized = True
  226. _announce_app_finalized(self)
  227. pending = self._pending
  228. while pending:
  229. maybe_evaluate(pending.popleft())
  230. for task in values(self._tasks):
  231. task.bind(self)
  232. def add_defaults(self, fun):
  233. if not callable(fun):
  234. d, fun = fun, lambda: d
  235. if self.configured:
  236. return self.conf.add_defaults(fun())
  237. self._pending_defaults.append(fun)
  238. def config_from_object(self, obj, silent=False, force=False):
  239. self._config_source = obj
  240. if force or self.configured:
  241. del(self.conf)
  242. return self.loader.config_from_object(obj, silent=silent)
  243. def config_from_envvar(self, variable_name, silent=False, force=False):
  244. module_name = os.environ.get(variable_name)
  245. if not module_name:
  246. if silent:
  247. return False
  248. raise ImproperlyConfigured(
  249. ERR_ENVVAR_NOT_SET.format(variable_name))
  250. return self.config_from_object(module_name, silent=silent, force=force)
  251. def config_from_cmdline(self, argv, namespace='celery'):
  252. self.conf.update(self.loader.cmdline_config_parser(argv, namespace))
  253. def setup_security(self, allowed_serializers=None, key=None, cert=None,
  254. store=None, digest='sha1', serializer='json'):
  255. from celery.security import setup_security
  256. return setup_security(allowed_serializers, key, cert,
  257. store, digest, serializer, app=self)
  258. def autodiscover_tasks(self, packages, related_name='tasks', force=False):
  259. if force:
  260. return self._autodiscover_tasks(packages, related_name)
  261. signals.import_modules.connect(promise(
  262. self._autodiscover_tasks, (packages, related_name),
  263. ), weak=False, sender=self)
  264. def _autodiscover_tasks(self, packages, related_name='tasks', **kwargs):
  265. # argument may be lazy
  266. packages = packages() if callable(packages) else packages
  267. self.loader.autodiscover_tasks(packages, related_name)
  268. def send_task(self, name, args=None, kwargs=None, countdown=None,
  269. eta=None, task_id=None, producer=None, connection=None,
  270. router=None, result_cls=None, expires=None,
  271. publisher=None, link=None, link_error=None,
  272. add_to_parent=True, reply_to=None, **options):
  273. task_id = task_id or uuid()
  274. producer = producer or publisher # XXX compat
  275. router = router or self.amqp.router
  276. conf = self.conf
  277. if conf.CELERY_ALWAYS_EAGER: # pragma: no cover
  278. warnings.warn(AlwaysEagerIgnored(
  279. 'CELERY_ALWAYS_EAGER has no effect on send_task',
  280. ), stacklevel=2)
  281. options = router.route(options, name, args, kwargs)
  282. if connection:
  283. producer = self.amqp.TaskProducer(connection)
  284. with self.producer_or_acquire(producer) as P:
  285. self.backend.on_task_call(P, task_id)
  286. task_id = P.publish_task(
  287. name, args, kwargs, countdown=countdown, eta=eta,
  288. task_id=task_id, expires=expires,
  289. callbacks=maybe_list(link), errbacks=maybe_list(link_error),
  290. reply_to=reply_to or self.oid, **options
  291. )
  292. result = (result_cls or self.AsyncResult)(task_id)
  293. if add_to_parent:
  294. parent = get_current_worker_task()
  295. if parent:
  296. parent.add_trail(result)
  297. return result
  298. def connection(self, hostname=None, userid=None, password=None,
  299. virtual_host=None, port=None, ssl=None,
  300. connect_timeout=None, transport=None,
  301. transport_options=None, heartbeat=None,
  302. login_method=None, failover_strategy=None, **kwargs):
  303. conf = self.conf
  304. return self.amqp.Connection(
  305. hostname or conf.BROKER_URL,
  306. userid or conf.BROKER_USER,
  307. password or conf.BROKER_PASSWORD,
  308. virtual_host or conf.BROKER_VHOST,
  309. port or conf.BROKER_PORT,
  310. transport=transport or conf.BROKER_TRANSPORT,
  311. ssl=self.either('BROKER_USE_SSL', ssl),
  312. heartbeat=heartbeat,
  313. login_method=login_method or conf.BROKER_LOGIN_METHOD,
  314. failover_strategy=(
  315. failover_strategy or conf.BROKER_FAILOVER_STRATEGY
  316. ),
  317. transport_options=dict(
  318. conf.BROKER_TRANSPORT_OPTIONS, **transport_options or {}
  319. ),
  320. connect_timeout=self.either(
  321. 'BROKER_CONNECTION_TIMEOUT', connect_timeout
  322. ),
  323. )
  324. broker_connection = connection
  325. @contextmanager
  326. def connection_or_acquire(self, connection=None, pool=True,
  327. *args, **kwargs):
  328. if connection:
  329. yield connection
  330. else:
  331. if pool:
  332. with self.pool.acquire(block=True) as connection:
  333. yield connection
  334. else:
  335. with self.connection() as connection:
  336. yield connection
  337. default_connection = connection_or_acquire # XXX compat
  338. @contextmanager
  339. def producer_or_acquire(self, producer=None):
  340. if producer:
  341. yield producer
  342. else:
  343. with self.amqp.producer_pool.acquire(block=True) as producer:
  344. yield producer
  345. default_producer = producer_or_acquire # XXX compat
  346. def prepare_config(self, c):
  347. """Prepare configuration before it is merged with the defaults."""
  348. return find_deprecated_settings(c)
  349. def now(self):
  350. return self.loader.now(utc=self.conf.CELERY_ENABLE_UTC)
  351. def mail_admins(self, subject, body, fail_silently=False):
  352. if self.conf.ADMINS:
  353. to = [admin_email for _, admin_email in self.conf.ADMINS]
  354. return self.loader.mail_admins(
  355. subject, body, fail_silently, to=to,
  356. sender=self.conf.SERVER_EMAIL,
  357. host=self.conf.EMAIL_HOST,
  358. port=self.conf.EMAIL_PORT,
  359. user=self.conf.EMAIL_HOST_USER,
  360. password=self.conf.EMAIL_HOST_PASSWORD,
  361. timeout=self.conf.EMAIL_TIMEOUT,
  362. use_ssl=self.conf.EMAIL_USE_SSL,
  363. use_tls=self.conf.EMAIL_USE_TLS,
  364. )
  365. def select_queues(self, queues=None):
  366. return self.amqp.queues.select(queues)
  367. def either(self, default_key, *values):
  368. """Fallback to the value of a configuration key if none of the
  369. `*values` are true."""
  370. return first(None, values) or self.conf.get(default_key)
  371. def bugreport(self):
  372. return bugreport(self)
  373. def _get_backend(self):
  374. from celery.backends import get_backend_by_url
  375. backend, url = get_backend_by_url(
  376. self.backend_cls or self.conf.CELERY_RESULT_BACKEND,
  377. self.loader)
  378. return backend(app=self, url=url)
  379. def on_configure(self):
  380. """Callback calld when the app loads configuration"""
  381. pass
  382. def _get_config(self):
  383. self.on_configure()
  384. if self._config_source:
  385. self.loader.config_from_object(self._config_source)
  386. self.configured = True
  387. s = Settings({}, [self.prepare_config(self.loader.conf),
  388. deepcopy(DEFAULTS)])
  389. # load lazy config dict initializers.
  390. pending = self._pending_defaults
  391. while pending:
  392. s.add_defaults(maybe_evaluate(pending.popleft()()))
  393. if self._preconf:
  394. for key, value in items(self._preconf):
  395. setattr(s, key, value)
  396. return s
  397. def _after_fork(self, obj_):
  398. self._maybe_close_pool()
  399. def _maybe_close_pool(self):
  400. if self._pool:
  401. self._pool.force_close_all()
  402. self._pool = None
  403. amqp = self.__dict__.get('amqp')
  404. if amqp is not None and amqp._producer_pool is not None:
  405. amqp._producer_pool.force_close_all()
  406. amqp._producer_pool = None
  407. def signature(self, *args, **kwargs):
  408. kwargs['app'] = self
  409. return self.canvas.signature(*args, **kwargs)
  410. def create_task_cls(self):
  411. """Creates a base task class using default configuration
  412. taken from this app."""
  413. return self.subclass_with_self(
  414. self.task_cls, name='Task', attribute='_app',
  415. keep_reduce=True, abstract=True,
  416. )
  417. def subclass_with_self(self, Class, name=None, attribute='app',
  418. reverse=None, keep_reduce=False, **kw):
  419. """Subclass an app-compatible class by setting its app attribute
  420. to be this app instance.
  421. App-compatible means that the class has a class attribute that
  422. provides the default app it should use, e.g.
  423. ``class Foo: app = None``.
  424. :param Class: The app-compatible class to subclass.
  425. :keyword name: Custom name for the target class.
  426. :keyword attribute: Name of the attribute holding the app,
  427. default is 'app'.
  428. """
  429. Class = symbol_by_name(Class)
  430. reverse = reverse if reverse else Class.__name__
  431. def __reduce__(self):
  432. return _unpickle_appattr, (reverse, self.__reduce_args__())
  433. attrs = dict({attribute: self}, __module__=Class.__module__,
  434. __doc__=Class.__doc__, **kw)
  435. if not keep_reduce:
  436. attrs['__reduce__'] = __reduce__
  437. return type(name or Class.__name__, (Class, ), attrs)
  438. def _rgetattr(self, path):
  439. return attrgetter(path)(self)
  440. def __repr__(self):
  441. return '<{0} {1}>'.format(type(self).__name__, appstr(self))
  442. def __reduce__(self):
  443. if self._using_v1_reduce:
  444. return self.__reduce_v1__()
  445. return (_unpickle_app_v2, (self.__class__, self.__reduce_keys__()))
  446. def __reduce_v1__(self):
  447. # Reduce only pickles the configuration changes,
  448. # so the default configuration doesn't have to be passed
  449. # between processes.
  450. return (
  451. _unpickle_app,
  452. (self.__class__, self.Pickler) + self.__reduce_args__(),
  453. )
  454. def __reduce_keys__(self):
  455. """Return keyword arguments used to reconstruct the object
  456. when unpickling."""
  457. return {
  458. 'main': self.main,
  459. 'changes': self.conf.changes,
  460. 'loader': self.loader_cls,
  461. 'backend': self.backend_cls,
  462. 'amqp': self.amqp_cls,
  463. 'events': self.events_cls,
  464. 'log': self.log_cls,
  465. 'control': self.control_cls,
  466. 'accept_magic_kwargs': self.accept_magic_kwargs,
  467. 'fixups': self.fixups,
  468. 'config_source': self._config_source,
  469. 'task_cls': self.task_cls,
  470. }
  471. def __reduce_args__(self):
  472. """Deprecated method, please use :meth:`__reduce_keys__` instead."""
  473. return (self.main, self.conf.changes,
  474. self.loader_cls, self.backend_cls, self.amqp_cls,
  475. self.events_cls, self.log_cls, self.control_cls,
  476. self.accept_magic_kwargs, self._config_source)
  477. @cached_property
  478. def Worker(self):
  479. return self.subclass_with_self('celery.apps.worker:Worker')
  480. @cached_property
  481. def WorkController(self, **kwargs):
  482. return self.subclass_with_self('celery.worker:WorkController')
  483. @cached_property
  484. def Beat(self, **kwargs):
  485. return self.subclass_with_self('celery.apps.beat:Beat')
  486. @cached_property
  487. def Task(self):
  488. return self.create_task_cls()
  489. @cached_property
  490. def annotations(self):
  491. return prepare_annotations(self.conf.CELERY_ANNOTATIONS)
  492. @cached_property
  493. def AsyncResult(self):
  494. return self.subclass_with_self('celery.result:AsyncResult')
  495. @cached_property
  496. def ResultSet(self):
  497. return self.subclass_with_self('celery.result:ResultSet')
  498. @cached_property
  499. def GroupResult(self):
  500. return self.subclass_with_self('celery.result:GroupResult')
  501. @cached_property
  502. def TaskSet(self): # XXX compat
  503. """Deprecated! Please use :class:`celery.group` instead."""
  504. return self.subclass_with_self('celery.task.sets:TaskSet')
  505. @cached_property
  506. def TaskSetResult(self): # XXX compat
  507. """Deprecated! Please use :attr:`GroupResult` instead."""
  508. return self.subclass_with_self('celery.result:TaskSetResult')
  509. @property
  510. def pool(self):
  511. if self._pool is None:
  512. _ensure_after_fork()
  513. limit = self.conf.BROKER_POOL_LIMIT
  514. self._pool = self.connection().Pool(limit=limit)
  515. return self._pool
  516. @property
  517. def current_task(self):
  518. return _task_stack.top
  519. @cached_property
  520. def oid(self):
  521. return oid_from(self)
  522. @cached_property
  523. def amqp(self):
  524. return instantiate(self.amqp_cls, app=self)
  525. @cached_property
  526. def backend(self):
  527. return self._get_backend()
  528. @cached_property
  529. def conf(self):
  530. return self._get_config()
  531. @cached_property
  532. def control(self):
  533. return instantiate(self.control_cls, app=self)
  534. @cached_property
  535. def events(self):
  536. return instantiate(self.events_cls, app=self)
  537. @cached_property
  538. def loader(self):
  539. return get_loader_cls(self.loader_cls)(app=self)
  540. @cached_property
  541. def log(self):
  542. return instantiate(self.log_cls, app=self)
  543. @cached_property
  544. def canvas(self):
  545. from celery import canvas
  546. return canvas
  547. @cached_property
  548. def tasks(self):
  549. self.finalize(auto=True)
  550. return self._tasks
  551. @cached_property
  552. def timezone(self):
  553. from celery.utils.timeutils import timezone
  554. conf = self.conf
  555. tz = conf.CELERY_TIMEZONE
  556. if not tz:
  557. return (timezone.get_timezone('UTC') if conf.CELERY_ENABLE_UTC
  558. else timezone.local)
  559. return timezone.get_timezone(self.conf.CELERY_TIMEZONE)
  560. App = Celery # compat