From b4af844409c0f6bda929c2d721665e5455db44ed Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Thu, 12 Jun 2025 20:23:07 +0200 Subject: [PATCH 1/3] Pass through timeout arguments for the client Signed-off-by: Mathias L. Baumann --- pyproject.toml | 2 +- src/frequenz/dispatch/_dispatcher.py | 12 +++++++++++- tests/test_managing_actor.py | 11 ++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 062a111..80f81d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ # plugins.mkdocstrings.handlers.python.import) "frequenz-sdk >= 1.0.0-rc1900, < 1.0.0-rc2100", "frequenz-channels >= 1.6.1, < 2.0.0", - "frequenz-client-dispatch >= 0.10.1, < 0.11.0", + "frequenz-client-dispatch >= 0.10.2, < 0.11.0", ] dynamic = ["version"] diff --git a/src/frequenz/dispatch/_dispatcher.py b/src/frequenz/dispatch/_dispatcher.py index 83dcb1d..d4eca69 100644 --- a/src/frequenz/dispatch/_dispatcher.py +++ b/src/frequenz/dispatch/_dispatcher.py @@ -198,12 +198,15 @@ async def run(): ``` """ + # pylint: disable-next=too-many-arguments def __init__( self, *, microgrid_id: int, server_url: str, key: str, + call_timeout: timedelta = timedelta(seconds=60), + stream_timeout: timedelta = timedelta(minutes=5), ): """Initialize the dispatcher. @@ -211,10 +214,17 @@ def __init__( microgrid_id: The microgrid id. server_url: The URL of the dispatch service. key: The key to access the service. + call_timeout: The timeout for API calls. + stream_timeout: The timeout for streaming API calls. """ super().__init__() - self._client = DispatchApiClient(server_url=server_url, key=key) + self._client = DispatchApiClient( + server_url=server_url, + key=key, + call_timeout=call_timeout, + stream_timeout=stream_timeout, + ) self._bg_service = DispatchScheduler( microgrid_id, self._client, diff --git a/tests/test_managing_actor.py b/tests/test_managing_actor.py index bdf1646..96c8a8e 100644 --- a/tests/test_managing_actor.py +++ b/tests/test_managing_actor.py @@ -327,9 +327,18 @@ async def test_manage_abstraction( class MyFakeClient(FakeClient): """Fake client for testing.""" - def __init__(self, *, server_url: str, key: str): + def __init__( + self, + *, + server_url: str, + key: str, + call_timeout: timedelta, + stream_timeout: timedelta, + ) -> None: assert server_url assert key + assert call_timeout + assert stream_timeout super().__init__() mid = 1 From b4fd9bf3c5ba1765ab12d79e24bde62174d1ac58 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Thu, 12 Jun 2025 20:24:06 +0200 Subject: [PATCH 2/3] Harden potentially flakey test ..by making sure it a dispatch expected to end will never repeat. Signed-off-by: Mathias L. Baumann --- tests/test_frequenz_dispatch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_frequenz_dispatch.py b/tests/test_frequenz_dispatch.py index e066f97..d030a7d 100644 --- a/tests/test_frequenz_dispatch.py +++ b/tests/test_frequenz_dispatch.py @@ -358,6 +358,7 @@ async def test_dispatch_schedule( active=True, duration=timedelta(seconds=10), type="TEST_TYPE", + recurrence=RecurrenceRule(), ) await test_env.client.create(**to_create_params(test_env.microgrid_id, sample)) # Get the initial dispatch state from the client to use as a base for comparison From bf019ef38ba4c854d4139649ab22ab05431d9e13 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Thu, 12 Jun 2025 20:26:18 +0200 Subject: [PATCH 3/3] Update release notes Signed-off-by: Mathias L. Baumann --- RELEASE_NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f0ee9d3..84796e0 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,7 +10,9 @@ ## New Features - +* The dispatcher offers two new parameters to control the client's call and stream timeout: + - `call_timeout`: The maximum time to wait for a response from the client. + - `stream_timeout`: The maximum time to wait before restarting a stream. ## Bug Fixes