Skip to content

Commit eae538a

Browse files
authored
Update BaseClient to support keepalive (frequenz-floss#104)
2 parents 5c89a00 + c1ba73d commit eae538a

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
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: 4 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

@@ -151,6 +151,8 @@ disable = [
151151
# pylint's unsubscriptable check is buggy and is not needed because
152152
# it is a type-check, for which we already have mypy.
153153
"unsubscriptable-object",
154+
# Checked by mypy
155+
"no-member",
154156
# Checked by flake8
155157
"redefined-outer-name",
156158
"unused-import",

src/frequenz/client/dispatch/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ async def display_help() -> None:
459459

460460

461461
# Add recurrence options to the create command
462-
create.params += recurrence_options # pylint: disable=no-member
462+
create.params += recurrence_options
463463
# Add recurrence options to the update command
464-
update.params += recurrence_options # pylint: disable=no-member
464+
update.params += recurrence_options
465465

466466

467467
def main() -> None:

src/frequenz/client/dispatch/_client.py

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

44
"""Dispatch API client for Python."""
5+
from __future__ import annotations
6+
57
from datetime import datetime, timedelta
68
from importlib.resources import files
79
from pathlib import Path
@@ -33,6 +35,7 @@
3335
from frequenz.client.base.channel import ChannelOptions, SslOptions
3436
from frequenz.client.base.client import BaseApiClient
3537
from frequenz.client.base.conversion import to_timestamp
38+
from frequenz.client.base.exception import ClientNotConnected
3639
from frequenz.client.base.retry import LinearBackoff
3740
from frequenz.client.base.streaming import GrpcStreamBroadcaster
3841

@@ -49,7 +52,7 @@
4952
DEFAULT_DISPATCH_PORT = 50051
5053

5154

52-
class Client(BaseApiClient[dispatch_pb2_grpc.MicrogridDispatchServiceStub]):
55+
class Client(BaseApiClient):
5356
"""Dispatch API client."""
5457

5558
streams: dict[
@@ -73,7 +76,6 @@ def __init__(
7376
"""
7477
super().__init__(
7578
server_url,
76-
dispatch_pb2_grpc.MicrogridDispatchServiceStub,
7779
connect=connect,
7880
channel_defaults=ChannelOptions(
7981
port=DEFAULT_DISPATCH_PORT,
@@ -88,6 +90,20 @@ def __init__(
8890
),
8991
)
9092
self._metadata = (("key", key),)
93+
self._setup_stub()
94+
95+
def _setup_stub(self) -> None:
96+
self._stub = cast(
97+
dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub,
98+
dispatch_pb2_grpc.MicrogridDispatchServiceStub(self.channel),
99+
)
100+
101+
@property
102+
def stub(self) -> dispatch_pb2_grpc.MicrogridDispatchServiceAsyncStub:
103+
"""The stub for the service."""
104+
if self._channel is None:
105+
raise ClientNotConnected(server_url=self.server_url, operation="stub")
106+
return self._stub
91107

92108
# pylint: disable=too-many-arguments, too-many-locals
93109
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)