__init__.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.task
  4. ~~~~~~~~~~~
  5. This is the old task module, it should not be used anymore,
  6. import from the main 'celery' module instead.
  7. If you're looking for the decorator implementation then that's in
  8. ``celery.app.base.Celery.task``.
  9. """
  10. from __future__ import absolute_import
  11. from celery._state import current_app, current_task as current
  12. from celery.__compat__ import MagicModule, recreate_module
  13. from celery.local import Proxy
  14. __all__ = [
  15. 'BaseTask', 'Task', 'PeriodicTask', 'task', 'periodic_task',
  16. 'group', 'chord', 'subtask', 'TaskSet',
  17. ]
  18. STATICA_HACK = True
  19. globals()['kcah_acitats'[::-1].upper()] = False
  20. if STATICA_HACK:
  21. # This is never executed, but tricks static analyzers (PyDev, PyCharm,
  22. # pylint, etc.) into knowing the types of these symbols, and what
  23. # they contain.
  24. from celery.canvas import group, chord, subtask
  25. from .base import BaseTask, Task, PeriodicTask, task, periodic_task
  26. from .sets import TaskSet
  27. class module(MagicModule):
  28. def __call__(self, *args, **kwargs):
  29. return self.task(*args, **kwargs)
  30. old_module, new_module = recreate_module(__name__, # pragma: no cover
  31. by_module={
  32. 'celery.task.base': ['BaseTask', 'Task', 'PeriodicTask',
  33. 'task', 'periodic_task'],
  34. 'celery.canvas': ['group', 'chord', 'subtask'],
  35. 'celery.task.sets': ['TaskSet'],
  36. },
  37. base=module,
  38. __package__='celery.task',
  39. __file__=__file__,
  40. __path__=__path__,
  41. __doc__=__doc__,
  42. current=current,
  43. discard_all=Proxy(lambda: current_app.control.purge),
  44. backend_cleanup=Proxy(
  45. lambda: current_app.tasks['celery.backend_cleanup']
  46. ),
  47. )