Skip to content

Commit 217b2e1

Browse files
committed
Update BaseClient to support keepalive
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 5c89a00 commit 217b2e1

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Frequenz Dispatch Client Library Release Notes
22

3+
## New Features
4+
5+
* Update BaseApiClient to get the http2 keepalive feature.
6+
37
## Bug Fixes
48

59
* Fix crash by adding the missing YEARLY frequency.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ requires-python = ">= 3.11, < 4"
3838
dependencies = [
3939
"typing-extensions >= 4.6.1, < 5",
4040
"frequenz-api-dispatch >= 0.15.1, < 0.16",
41-
"frequenz-client-base >= 0.6.0, < 0.7.0",
41+
"frequenz-client-base >= 0.7.0, < 0.8.0",
4242
"frequenz-client-common >= 0.1.0, < 0.3.0",
43-
"grpcio >= 1.64.1, < 2",
43+
"grpcio >= 1.66.1, < 2",
4444
]
4545
dynamic = ["version"]
4646

src/frequenz/client/dispatch/_client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
33

44
"""Dispatch API client for Python."""
5+
56
from datetime import datetime, timedelta
67
from importlib.resources import files
78
from pathlib import Path
@@ -33,6 +34,7 @@
3334
from frequenz.client.base.channel import ChannelOptions, SslOptions
3435
from frequenz.client.base.client import BaseApiClient
3536
from frequenz.client.base.conversion import to_timestamp
37+
from frequenz.client.base.exception import ClientNotConnected
3638
from frequenz.client.base.retry import LinearBackoff
3739
from frequenz.client.base.streaming import GrpcStreamBroadcaster
3840

@@ -49,7 +51,7 @@
4951
DEFAULT_DISPATCH_PORT = 50051
5052

5153

52-
class Client(BaseApiClient[dispatch_pb2_grpc.MicrogridDispatchServiceStub]):
54+
class Client(BaseApiClient):
5355
"""Dispatch API client."""
5456

5557
streams: dict[
@@ -73,7 +75,6 @@ def __init__(
7375
"""
7476
super().__init__(
7577
server_url,
76-
dispatch_pb2_grpc.MicrogridDispatchServiceStub,
7778
connect=connect,
7879
channel_defaults=ChannelOptions(
7980
port=DEFAULT_DISPATCH_PORT,
@@ -88,6 +89,20 @@ def __init__(
8889
),
8990
)
9091
self._metadata = (("key", key),)
92+
self._setup_stub()
93+
94+
def _setup_stub(self) -> None:
95+
self._stub = cast(
96+
"dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub",
97+
dispatch_pb2_grpc.MicrogridDispatchServiceStub(self.channel),
98+
)
99+
100+
@property
101+
def stub(self) -> "dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub":
102+
"""The stub for the service."""
103+
if self._channel is None:
104+
raise ClientNotConnected(server_url=self.server_url, operation="stub")
105+
return self._stub
91106

92107
# pylint: disable=too-many-arguments, too-many-locals
93108
async def list(

src/frequenz/client/dispatch/test/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def stub(self) -> FakeService: # type: ignore
3434
"""
3535
return self._stuba
3636

37+
def _setup_stub(self) -> None:
38+
"""Empty body because no setup needed."""
39+
3740
def dispatches(self, microgrid_id: int) -> list[Dispatch]:
3841
"""List of dispatches.
3942

0 commit comments

Comments
 (0)