Skip to content

Commit

Permalink
Create documentation page about events (#152)
Browse files Browse the repository at this point in the history
* Fill out correlation IDs

* Fill out correlation ID header name

* Add intro

* Correct spelling
  • Loading branch information
callumforrester authored May 11, 2023
1 parent 76a4e02 commit c4b95d2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/developer/explanations/events.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Events Emitted by the Worker
============================

Blueapi adds new events on top of the `bluesky event model`_.

Reasons
-------

Since the ``RunEngine`` is traditionally used by a human in front of an IPython terminal, it
sometimes assumes intuitive behaviour. The worker replaces the human and so must fill in the
gaps.

The base engine programatically emits data events conforming to the `bluesky event model`_. These
are meant to be handled by other subscribing code (e.g. databroker) and are decoupled from concerns such as whether
a plan has started, finished, paused, errored etc. See the example below:

.. figure:: ../../images/bluesky-events.png
:width: 600px
:align: center

sequence of event emission compared to plan start/finish, in a complicated case

Note the gap between the start of the plan and the issue of the first `run start document`_, and the similar gap
for the stop document vs end of the plan, thsse are typically used for setup and cleanup.
Also note that a plan can produce an arbitrary number of runs. This decoupling is fine in an IPython terminal
because a human user can see when a plan has started, can see when it's finished and can see which runs are
associated with which plans.

New Events
----------

For the case of automation, we introduce a new set of events outside of the event model, specifically
pertaining to the running of the plan and state of the ``RunEngine``. At a mimimum, an event is emitted
every time the engine:

* Starts a new plan
* Completes a plan
* Fails/errors

In the latter case, information about the error is also included.


Correlation ID
--------------

When controlling plans programatically, it can be useful to verify that event model documents really are related to
the plan you just asked the worker to run. The worker will therefore bundle a correlation ID into the headers of
messages containing documents.

.. seealso:: `Microsoft Playbook on Correlation IDs`_

ActiveMQ will give this header a different name depending on the protocol you use.

.. list-table:: Correlation ID Headers
:widths: 25 25
:header-rows: 1

* - Protocol
- Header name
* - JMS
- jms_correlationID
* - STOMP
- correlation-id

.. _`bluesky event model`: https://blueskyproject.io/event-model/main/index.html
.. _`run start document`: https://blueskyproject.io/event-model/main/user/explanations/data-model.html#run-start-document
.. _`Microsoft Playbook on Correlation IDs`: https://microsoft.github.io/code-with-engineering-playbook/observability/correlation-id/
1 change: 1 addition & 0 deletions docs/developer/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ side-bar.
explanations/architecture
explanations/lifecycle
explanations/type_validators
explanations/events

+++

Expand Down
Binary file added docs/images/bluesky-events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c4b95d2

Please sign in to comment.