Skip to content

Commit

Permalink
Add 'filter' option to event-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fqqb committed Oct 17, 2024
1 parent 7eea7d5 commit 27a0363
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions yamcs-client/src/yamcs/archive/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ def list_events(
source: Optional[str] = None,
severity: Optional[str] = None,
text_filter: Optional[str] = None,
filter: Optional[str] = None,
start: Optional[datetime] = None,
stop: Optional[datetime] = None,
page_size: int = 500,
Expand All @@ -598,6 +599,11 @@ def list_events(
``CRITICAL`` or ``SEVERE``.
:param text_filter:
Filter the text message of the returned events
:param filter:
Filter query, allows for both text and field search.
.. versionadded:: 1.10.1
Compatible with Yamcs v5.10.2 onwards
:param start:
Minimum start date of the returned events (inclusive)
:param stop:
Expand Down Expand Up @@ -625,6 +631,8 @@ def list_events(
params["stop"] = to_isostring(stop)
if text_filter is not None:
params["q"] = text_filter
if filter is not None:
params["filter"] = filter

return pagination.Iterator(
ctx=self.ctx,
Expand All @@ -640,6 +648,7 @@ def stream_events(
source: Optional[Union[str, List[str]]] = None,
severity: Optional[str] = None,
text_filter: Optional[str] = None,
filter: Optional[str] = None,
start: Optional[datetime] = None,
stop: Optional[datetime] = None,
chunk_size: int = 32 * 1024,
Expand All @@ -657,6 +666,12 @@ def stream_events(
``CRITICAL`` or ``SEVERE``.
:param text_filter:
Filter the text message of the returned events
:param filter:
Filter query applied to returned events. Allows for both text
and field search.
.. versionadded:: 1.10.1
Compatible with Yamcs v5.10.2 onwards
:param start:
Minimum generation time of the returned events (inclusive)
:param stop:
Expand All @@ -676,6 +691,8 @@ def stream_events(
options.stop.MergeFrom(to_server_time(stop))
if text_filter is not None:
options.q = text_filter
if filter is not None:
options.filter = filter

def generate():
path = f"/stream-archive/{self._instance}:streamEvents"
Expand Down
15 changes: 14 additions & 1 deletion yamcs-client/src/yamcs/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,11 @@ def create_time_subscription(
return subscription

def create_event_subscription(
self, instance: str, on_data: Callable[[Event], None], timeout: float = 60
self,
instance: str,
on_data: Callable[[Event], None],
filter: Optional[str] = None,
timeout: float = 60,
) -> WebSocketSubscriptionFuture:
"""
Create a new subscription for receiving events of an instance.
Expand All @@ -758,6 +762,12 @@ def create_event_subscription(
A Yamcs instance name
:param on_data:
Function that gets called on each :class:`.Event`.
:param filter:
Filter query applied to returned events. Allows for both text
and field search.
.. versionadded:: 1.10.1
Compatible with Yamcs v5.10.2 onwards
:param timeout:
The amount of seconds to wait for the request to complete.
:return:
Expand All @@ -766,6 +776,9 @@ def create_event_subscription(
"""
options = events_service_pb2.SubscribeEventsRequest()
options.instance = instance
if filter is not None:
options.filter = filter

manager = WebSocketSubscriptionManager(
self.ctx, topic="events", options=options
)
Expand Down

0 comments on commit 27a0363

Please sign in to comment.