pyfebiopt.monitoring.events
===========================

.. py:module:: pyfebiopt.monitoring.events

.. autoapi-nested-parse::

   Socket helpers and envelopes for emitting monitor events.



Classes
-------

.. autoapisummary::

   pyfebiopt.monitoring.events.EventEmitter
   pyfebiopt.monitoring.events.NullEventEmitter
   pyfebiopt.monitoring.events.SocketEventEmitter
   pyfebiopt.monitoring.events.EventConsumer
   pyfebiopt.monitoring.events.EventSocketListener


Functions
---------

.. autoapisummary::

   pyfebiopt.monitoring.events.create_event_emitter


Module Contents
---------------

.. py:class:: EventEmitter

   Abstract emitter interface for monitor events.


   .. py:method:: emit(job_id: str, event: str, payload: dict[str, Any]) -> None
      :abstractmethod:


      Send a single event payload for the given job.



.. py:class:: NullEventEmitter

   Bases: :py:obj:`EventEmitter`


   Drop events without raising when the monitor is unavailable.


   .. py:method:: emit(job_id: str, event: str, payload: dict[str, Any]) -> None

      Ignore the event entirely.



.. py:class:: SocketEventEmitter(socket_path: pathlib.Path)

   Bases: :py:obj:`EventEmitter`


   Emit monitor events through a UNIX domain socket.

   Keep the socket path for future emission attempts.


   .. py:attribute:: socket_path


   .. py:method:: emit(job_id: str, event: str, payload: dict[str, Any]) -> None

      Send the serialized envelope to the monitor.



.. py:function:: create_event_emitter(socket_path: pathlib.Path | None) -> EventEmitter

   Return an emitter that targets the provided socket path.


.. py:class:: EventConsumer

   Bases: :py:obj:`Protocol`


   Protocol for objects that consume monitor events.


   .. py:method:: apply_event(job_id: str, event: str, payload: dict[str, Any], ts: float) -> None


.. py:class:: EventSocketListener(socket_path: pathlib.Path, consumer: EventConsumer)

   Listen for monitor events over a UNIX socket.

   Track the path and consumer for the incoming stream.


   .. py:attribute:: socket_path


   .. py:attribute:: consumer


   .. py:method:: start() -> None

      Start listening for upstream monitor events.



   .. py:method:: stop() -> None

      Stop listening and clean up the socket resources.



