Skip to content

Commit

Permalink
Improved custom stamping visitor documentation (celery#7745)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus authored Sep 7, 2022
1 parent afe0c23 commit aecbeda
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/userguide/canvas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ pattern. The class that implements this custom logic must
inherit ``VisitorStamping`` and implement appropriate methods.

For example, the following example ``InGroupVisitor`` will label
tasks that are in side of some group by lable ``in_group``.
tasks that are in side of some group by label ``in_group``.

.. code-block:: python
Expand All @@ -1221,3 +1221,33 @@ tasks that are in side of some group by lable ``in_group``.
def on_signature(self, sig, **headers) -> dict:
return {"in_group": [self.in_group], "stamped_headers": ["in_group"]}
The following example shows another custom stamping visitor, which labels all
tasks with a custom ``monitoring_id`` which can represent a UUID value of an external monitoring system,
that can be used to track the task execution by including the id with such a visitor implementation.
This ``monitoring_id`` can be a randomly generated UUID, or a unique identifier of the span id used by
the external monitoring system.

.. code-block:: python
class MonitoringIdStampingVisitor(StampingVisitor):
def on_signature(self, sig, **headers) -> dict:
return {'monitoring_id': uuid4(), 'stamped_headers': ['monitoring_id']}
Next, lets see how to use the ``MonitoringIdStampingVisitor`` stamping visitor.

.. code-block:: python
sig_example = signature('t1')
sig_example.stamp(visitor=MonitoringIdStampingVisitor())
group_example = group([signature('t1'), signature('t2')])
group_example.stamp(visitor=MonitoringIdStampingVisitor())
chord_example = chord([signature('t1'), signature('t2')], signature('t3'))
chord_example.stamp(visitor=MonitoringIdStampingVisitor())
chain_example = chain(signature('t1'), group(signature('t2'), signature('t3')), signature('t4'))
chain_example.stamp(visitor=MonitoringIdStampingVisitor())
Lastly, it's important to mention that each monitoring id stamp in the example above would be different from each other between tasks.

0 comments on commit aecbeda

Please sign in to comment.