herostools.actor.archiver.base
==============================

.. py:module:: herostools.actor.archiver.base


Classes
-------

.. autoapisummary::

   herostools.actor.archiver.base.HERODataArchiver


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

.. py:class:: HERODataArchiver(object_selector: str, event_name: str, default_metadata: dict | None = None, max_retries: int = 5, *args, **kwargs)

   Bases: :py:obj:`heros.EventObserver`


   Base EventObserver that subscribes to a HERO event and archives its payload.

   The event payload may be a ``(data, metadata)`` tuple or a plain dict.
   Subclasses implement :meth:`_store`.

   :param object_selector: Zenoh object selector for the devices to subscribe to.
   :param event_name: Name of the event.
   :param default_metadata: Default metadata merged with every incoming payload's metadata.
   :param max_retries: Number of times to retry a failed store before dropping the item.


   .. py:attribute:: metadata


   .. py:attribute:: max_retries
      :value: 5



   .. py:attribute:: _payload_queue


   .. py:attribute:: _stop_event


   .. py:attribute:: _worker_thread


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

      Background worker that consumes the payload queue.



   .. py:method:: is_queue_drained() -> bool

      Return True when all queued items have been processed.

      :returns: True if every item put on the queue has had task_done() called.



   .. py:method:: _stop()

      Stop the background thread gracefully.



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

      Called by boss on shutdown.



   .. py:method:: feed(source_name: str, data: Iterable, retry_count: int = 0) -> None

      Callback registered with the source event.

      ``data`` may be a ``(payload, metadata)`` tuple or a plain dict.
      When a plain dict is received it is used as both payload and metadata
      so downstream ``_store`` implementations can still locate identifier
      keys regardless of which field they are in.

      :param source_name: Name of the event source (the HERO).
      :param data: Either a ``(payload, metadata)`` tuple or a plain dict payload.
      :param retry_count: Number of times this item has already been retried.



   .. py:method:: _store(source_name: str, payload: Any, metadata: dict) -> None
      :abstractmethod:


      Store the payload.  Must be implemented by subclasses.

      :param source_name: Name of the event source (the HERO).
      :param payload: The actual data.
      :param metadata: Incoming metadata merged with ``default_metadata``.



