Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename 'GRPCClient.run()' #2156

Merged
merged 5 commits into from
Jan 17, 2025
Merged

Rename 'GRPCClient.run()' #2156

merged 5 commits into from
Jan 17, 2025

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jan 14, 2025

Motivation:

To support swift-service-lifecycle the grpc client and server types will conform to its 'Service' protocol. This has a requirement for a method called 'run()'. Ideally this would respect graceful shutdown. We can't do this with the current client as we already have a run method. To do this we'd need to wrap the type and redeclare all of it's methods. Using a wrapper isn't a good user experience.

Modifications:

  • Rename run to 'maintainConnections()'
  • Deprecate 'run()', we'll remove this later

Result:

  • run is deprecated

Motivation:

To support swift-service-lifecycle the grpc client and server types will
conform to its 'Service' protocol. This has a requirement for a method
called 'run()'. Ideally this would respect graceful shutdown. We can't
do this with the current client as we already have a run method. To do
this we'd need to wrap the type and redeclare all of it's methods. Using
a wrapper isn't a good user experience.

Modifications:

- Rename run to 'maintainConnections()'
- Deprecate 'run()', we'll remove this later

Result:

- run is deprecated
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Jan 14, 2025
@glbrntt glbrntt requested a review from gjcairo January 14, 2025 16:49
@glbrntt glbrntt marked this pull request as ready for review January 14, 2025 16:49
Copy link
Collaborator

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully following why removing run allows us to adopt service lifecycle? Why don't we keep the method and add the graceful shutdown handling in there?

@glbrntt
Copy link
Collaborator Author

glbrntt commented Jan 14, 2025

I'm not fully following why removing run allows us to adopt service lifecycle? Why don't we keep the method and add the graceful shutdown handling in there?

Because lifecycle support will be added in -extras and run() needs to know about the with-graceful-shutdown handler.

In -extras we can't reimplement run() because it already exists so any implementation would either have to forgo graceful shutdown (not good) or wrap the client (also not good).

@FranzBusch
Copy link
Collaborator

Because lifecycle support will be added in -extras and run() needs to know about the with-graceful-shutdown handler.

In -extras we can't reimplement run() because it already exists so any implementation would either have to forgo graceful shutdown (not good) or wrap the client (also not good).

I see. What do you think about using package traits to add support for swift-service-lifecycle in this package?

@glbrntt
Copy link
Collaborator Author

glbrntt commented Jan 16, 2025

Because lifecycle support will be added in -extras and run() needs to know about the with-graceful-shutdown handler.
In -extras we can't reimplement run() because it already exists so any implementation would either have to forgo graceful shutdown (not good) or wrap the client (also not good).

I see. What do you think about using package traits to add support for swift-service-lifecycle in this package?

I'd rather we just did it now to be honest. Presumably traits would require us to have multiple package manifest as well which is something I'd like to avoid. We can always support via traits later as well.

Copy link
Collaborator

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall but left a question about the rename

@@ -208,7 +208,7 @@ public final class GRPCClient: Sendable {
///
/// The client, and by extension this function, can only be run once. If the client is already
/// running or has already been closed then a ``RuntimeError`` is thrown.
public func run() async throws {
public func maintainConnections() async throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:
I (think I) understand why maintainConnection instead of connect - because it's async thus a long-running task and the act of just connecting doesn't imply it runs for a long period of time. But I find the naming still a bit weird. Did you consider something like connectAndRun()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, I wasn't 100% happy with the name.

Broadly speaking this function is:

  • long running
  • meant to be run in the background
  • will manage any underlying connections

I think maintainConnections does an okay job at capturing that. Some alternatives:

  • connectAndRun
  • runBackgroundWork
  • runBackgroundTasks
  • manageConnections
  • runConnections

WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think runConnections, manageConnections and (I'll add a third one) startAndRunConnections achieve the three goals you listed the best.

@glbrntt glbrntt requested a review from gjcairo January 17, 2025 09:33
Copy link
Collaborator

@gjcairo gjcairo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks George!

@glbrntt glbrntt enabled auto-merge (squash) January 17, 2025 09:47
@glbrntt glbrntt merged commit eafb334 into grpc:main Jan 17, 2025
31 of 33 checks passed
@glbrntt glbrntt deleted the v2/rename-run branch January 17, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants