|
@@ -28,9 +28,12 @@ Example connecting to the :signal:`after_task_publish` signal:
|
|
|
from celery.signals import after_task_publish
|
|
|
|
|
|
@after_task_publish.connect
|
|
|
- def task_sent_handler(sender=None, body=None, **kwargs):
|
|
|
- print('after_task_publish for task id {body[id]}'.format(
|
|
|
- body=body,
|
|
|
+ def task_sent_handler(sender=None, headers=None, body=None, **kwargs):
|
|
|
+ # information about task are located in headers for task messages
|
|
|
+ # using the task protocol version 2.
|
|
|
+ info = headers if 'task' in headers else body
|
|
|
+ print('after_task_publish for task id {info[id]}'.format(
|
|
|
+ info=info,
|
|
|
))
|
|
|
|
|
|
|
|
@@ -44,9 +47,12 @@ is published:
|
|
|
.. code-block:: python
|
|
|
|
|
|
@after_task_publish.connect(sender='proj.tasks.add')
|
|
|
- def task_sent_handler(sender=None, body=None, **kwargs):
|
|
|
- print('after_task_publish for task id {body[id]}'.format(
|
|
|
- body=body,
|
|
|
+ def task_sent_handler(sender=None, headers=None, body=None, **kwargs):
|
|
|
+ # information about task are located in headers for task messages
|
|
|
+ # using the task protocol version 2.
|
|
|
+ info = headers if 'task' in headers else body
|
|
|
+ print('after_task_publish for task id {info[id]}'.format(
|
|
|
+ info=info,
|
|
|
))
|
|
|
|
|
|
Signals use the same implementation as django.core.dispatch. As a result other
|
|
@@ -123,9 +129,16 @@ Sender is the name of the task being sent.
|
|
|
|
|
|
Provides arguments:
|
|
|
|
|
|
+* headers
|
|
|
+
|
|
|
+ The task message headers, see :ref:`task-message-protocol-v2`
|
|
|
+ and :ref:`task-message-protocol-v1`.
|
|
|
+ for a reference of possible fields that can be defined.
|
|
|
+
|
|
|
* body
|
|
|
|
|
|
- The task message body, see :ref:`task-message-protocol-v1`
|
|
|
+ The task message body, see :ref:`task-message-protocol-v2`
|
|
|
+ and :ref:`task-message-protocol-v1`.
|
|
|
for a reference of possible fields that can be defined.
|
|
|
|
|
|
* exchange
|