__init__.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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',
  16. 'task', 'periodic_task',
  17. 'group', 'chord', 'subtask', 'TaskSet',
  18. ]
  19. # This is for static analyzers
  20. BaseTask = object
  21. Task = object
  22. PeriodicTask = object
  23. task = lambda *a, **kw: None
  24. periodic_task = lambda *a, **kw: None
  25. group = lambda *a, **kw: None
  26. chord = lambda *a, **kw: None
  27. subtask = lambda *a, **kw: None
  28. TaskSet = object
  29. class module(MagicModule):
  30. def __call__(self, *args, **kwargs):
  31. return self.task(*args, **kwargs)
  32. old_module, new_module = recreate_module(__name__, # pragma: no cover
  33. by_module={
  34. 'celery.task.base': ['BaseTask', 'Task', 'PeriodicTask',
  35. 'task', 'periodic_task'],
  36. 'celery.canvas': ['chain', 'group', 'chord', 'subtask'],
  37. 'celery.task.sets': ['TaskSet'],
  38. },
  39. base=module,
  40. __package__='celery.task',
  41. __file__=__file__,
  42. __path__=__path__,
  43. __doc__=__doc__,
  44. current=current,
  45. discard_all=Proxy(lambda: current_app.control.purge),
  46. backend_cleanup=Proxy(
  47. lambda: current_app.tasks['celery.backend_cleanup']
  48. ),
  49. )