Skip to content

Commit a696d43

Browse files
committed
Add support to restart a stream
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 97946f0 commit a696d43

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Features
44

55
* Added support for HMAC signing of client messages
6+
* Added support for streams to be restarted without their channel being closed
67

78
## Upgrading
89

src/frequenz/client/base/streaming.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ def new_receiver(
7777
limit=maxsize, warn_on_overflow=warn_on_overflow
7878
)
7979

80+
def reconnect(self) -> None:
81+
"""Reconnect to the stream.
82+
83+
This will cancel the current task and create a new one.
84+
"""
85+
if not self._task.done():
86+
_logger.warning(
87+
"%s: reconnecting to the stream, cancelling the current task",
88+
self._stream_name,
89+
)
90+
self._task.cancel()
91+
self._task = asyncio.create_task(self._run())
92+
8093
@property
8194
def is_running(self) -> bool:
8295
"""Return whether the streaming helper is running.

0 commit comments

Comments
 (0)