Skip to content

Commit

Permalink
Raise exception in stream() on connection loss
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
  • Loading branch information
Marenz committed Sep 26, 2024
1 parent aec339d commit d5dbc25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Upgrading

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
* `Client.stream()` will now raise an Exception when the connection is lost.

## New Features

Expand Down
7 changes: 7 additions & 0 deletions src/frequenz/client/dispatch/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from frequenz.client.base.channel import ChannelOptions, SslOptions
from frequenz.client.base.client import BaseApiClient
from frequenz.client.base.conversion import to_timestamp
from frequenz.client.base.retry import LinearBackoff
from frequenz.client.base.streaming import GrpcStreamBroadcaster

from ._internal_types import DispatchCreateRequest
Expand Down Expand Up @@ -208,6 +209,11 @@ def _get_stream(
) -> GrpcStreamBroadcaster[StreamMicrogridDispatchesResponse, DispatchEvent]:
"""Get an instance to the streaming helper."""
broadcaster = self.streams.get(microgrid_id)
# pylint: disable=protected-access
if broadcaster is not None and broadcaster._channel.is_closed:
# pylint: enable=protected-access
del self.streams[microgrid_id]
broadcaster = None
if broadcaster is None:
request = StreamMicrogridDispatchesRequest(microgrid_id=microgrid_id)
broadcaster = GrpcStreamBroadcaster(
Expand All @@ -219,6 +225,7 @@ def _get_stream(
),
),
transform=DispatchEvent.from_protobuf,
retry_strategy=LinearBackoff(interval=1, limit=0),
)
self.streams[microgrid_id] = broadcaster

Expand Down

0 comments on commit d5dbc25

Please sign in to comment.