Browse Source

Added some more information to celery.signals documentation

Ask Solem 14 years ago
parent
commit
ffaf6d486d
1 changed files with 44 additions and 0 deletions
  1. 44 0
      docs/reference/celery.signals.rst

+ 44 - 0
docs/reference/celery.signals.rst

@@ -6,12 +6,49 @@ Signals - celery.signals
     :local:
 .. currentmodule:: celery.signals
 
+Basics
+======
+
+Several kinds of events trigger signals, you can connect to these signals
+to perform actions as they trigger.
+
+Example connecting to the :data:`task_sent` signal:
+
+.. code-block:: python
+
+    from celery.signals import task_sent
+
+    def task_sent_handler(sender=None, task_id=None, task=None, args=None,
+            kwargs=None, \*\*kwds):
+        print("Got signal task_sent for task id %s" % (task_id, ))
+
+    task_sent.connect(task_sent_handler)
+
+
+Some signals also have a sender which you can filter by. For example the
+:data:`task_sent` signal uses the task name as a sender, so you can
+connect your handler to be called only when tasks with name ``"tasks.add"``
+has been sent by providing the ``sender`` argument to
+:class:`~celery.utils.dispatch.signal.Signal.connect`:
+
+.. code-block:: python
+
+    task_sent.connect(task_sent_handler, sender="tasks.add")
+
+Signals
+=======
+
+Task Signals
+------------
+
 .. data:: task_sent
 
     Triggered when a task has been sent to the broker.
     Note that this is executed in the client process, the one sending
     the task, not in the worker.
 
+    Sender is the name of the task being sent.
+
     Provides arguments:
 
     * task_id
@@ -36,6 +73,8 @@ Signals - celery.signals
 
     Triggered before a task is executed.
 
+    Sender is the task class being executed.
+
     Provides arguments:
 
     * task_id
@@ -54,6 +93,8 @@ Signals - celery.signals
 
     Triggered after a task has been executed.
 
+    Sender is the task class executed.
+
     Provides arguments:
 
     * task_id
@@ -72,6 +113,9 @@ Signals - celery.signals
 
         The return value of the task.
 
+Worker Signals
+--------------
+
 .. data:: worker_init
 
     Triggered before the worker is started.