Skip to content

Add a BaseApiClient class#56

Merged
llucax merged 4 commits intofrequenz-floss:v0.x.xfrom
llucax:base-client
Jun 3, 2024
Merged

Add a BaseApiClient class#56
llucax merged 4 commits intofrequenz-floss:v0.x.xfrom
llucax:base-client

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented May 31, 2024

This class abstracts the common functionality of all the API clients. It provides a way to connect and disconnect from the server, provided as a URL, and a way to create the stubs to interact with the server.

It also provides an async context manager to make sure the connection is closed when the client is done.

We also add a new ClientNotConnected exception that is raised when performing operation on a client that is not connected to the server.

@llucax llucax requested a review from a team as a code owner May 31, 2024 16:12
@llucax llucax requested a review from Marenz May 31, 2024 16:12
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:code Affects the code in general labels May 31, 2024
@llucax llucax linked an issue May 31, 2024 that may be closed by this pull request
@llucax llucax self-assigned this May 31, 2024
@llucax llucax modified the milestone: v0.5.0 May 31, 2024
@llucax llucax requested a review from cwasicki May 31, 2024 16:20
@llucax

This comment was marked as outdated.

@llucax llucax marked this pull request as draft May 31, 2024 16:21
@llucax llucax marked this pull request as ready for review June 3, 2024 08:39
@llucax llucax enabled auto-merge June 3, 2024 08:39
@llucax
Copy link
Contributor Author

llucax commented Jun 3, 2024

#54 merged, this is ready for review. I enabled auto-merge.

@llucax
Copy link
Contributor Author

llucax commented Jun 3, 2024

FYI, I'm planning to add support to easily wrap stub methods having automatic retry using retry strategies, and to have also an easy way to wrap streaming methods by having a list of GrpcStreamBroadcaster internally, which is something every client having streaming methods need to do. All of this in follow-up PRs, not this one, but just so you know where is this heading.

llucax added 4 commits June 3, 2024 10:50
This class abstracts the common functionality of all the API clients.
It provides a way to connect and disconnect from the server, provided as
a URL, and a way to create the stubs to interact with the server.

It also provides an async context manager to make sure the connection is
closed when the client is done.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This exception will be raised when making operations on the client that
is not connected to the server.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
When the client is not connected there is no `stub` or `channel` that
can be retrieved, so we raise an exception instead of returning `None`.

This is much more convenient, as otherwise one must `assert is not None`
each time those properties are used, and most of the time one will use
them when it is expected that the client is connected.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax added this pull request to the merge queue Jun 3, 2024
Merged via the queue into frequenz-floss:v0.x.x with commit 7451115 Jun 3, 2024
@llucax llucax deleted the base-client branch June 3, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:code Affects the code in general part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a GrpcApiClient base class

2 participants