瀏覽代碼

Adds Celery.current_task

Ask Solem 13 年之前
父節點
當前提交
313b71fd68
共有 2 個文件被更改,包括 9 次插入1 次删除
  1. 5 1
      celery/app/base.py
  2. 4 0
      docs/reference/celery.rst

+ 5 - 1
celery/app/base.py

@@ -27,7 +27,7 @@ from celery import platforms
 from celery.exceptions import AlwaysEagerIgnored
 from celery.loaders import get_loader_cls
 from celery.local import PromiseProxy, maybe_evaluate
-from celery.state import _tls, get_current_app
+from celery.state import _task_stack, _tls, get_current_app
 from celery.utils.functional import first
 from celery.utils.imports import instantiate, symbol_by_name
 
@@ -391,6 +391,10 @@ class Celery(object):
                             limit=self.conf.BROKER_POOL_LIMIT)
         return self._pool
 
+    @property
+    def current_task(self):
+        return _task_stack.top
+
     @cached_property
     def amqp(self):
         """Sending/receiving messages.  See :class:`~celery.app.amqp.AMQP`."""

+ 4 - 0
docs/reference/celery.rst

@@ -36,6 +36,10 @@ Application
 
         Current configuration.
 
+    .. attribute:: current_task
+
+        The instance of the task that is being executed, or :const:`None`.
+
     .. attribute:: amqp
 
         AMQP related functionality: :class:`~@amqp`.