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

[PLAT-742] Adds ReconnectCallback to ws go-client #440

Merged

Conversation

kschoche
Copy link
Contributor

@kschoche kschoche commented Sep 3, 2024

Adds a ReconnectCallback to the websocket go-client, useful for client side management of reconnects which are otherwise not exposed to the user.

The new callback functionality can be consumed similarly to the way it is used in the unit tests or similarly to this:

	reconnectCallback := func(err error) {
		reconnectCounter++
		if err != nil {
			logger.Errorf("unable to reconnect, retrying %d: %v", reconnectCounter, err.Error())
		} else {
			logger.Info("reconnect successful")
		}
	}

	client, err := polygonws.New(polygonws.Config{ReconnectCallback: reconnectCallback,   ...})

@kschoche kschoche self-assigned this Sep 3, 2024
@kschoche kschoche marked this pull request as ready for review September 4, 2024 15:37
Copy link
Contributor

@jbonzo jbonzo left a comment

Choose a reason for hiding this comment

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

lgtm. Might want to get someone else's review as well, someone not on our team to get a different perspective

@justinpolygon
Copy link
Contributor

justinpolygon commented Sep 4, 2024

Hey @kschoche, thanks for submitting this pull request to add the ReconnectCallback functionality! It's great to see contributions that aim to extend flexibility and control. This could be really helpful for providing more transparency and customization in how reconnections are handled, such as allowing for custom logging, error handling, or even modifying reconnection strategies.

Could you share a bit more about the specific scenarios or issues that prompted this addition? For instance, were there cases where the existing auto-reconnect functionality wasn't meeting certain needs, or perhaps you've encountered situations where additional control over the reconnection process would be beneficial? I'm just wondering if we need to adjust the default reconnection behavior based on what prompted this.

Copy link
Contributor

@justinpolygon justinpolygon left a comment

Choose a reason for hiding this comment

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

LGTM

@kschoche
Copy link
Contributor Author

kschoche commented Sep 4, 2024

Could you share a bit more about the specific scenarios or issues that prompted this addition? For instance, were there cases where the existing auto-reconnect functionality wasn't meeting certain needs, or perhaps you've encountered situations where additional control over the reconnection process would be beneficial? I'm just wondering if we need to adjust the default reconnection behavior based on what prompted this.

Thanks @justinpolygon!
This is mostly just to expose the reconnect process a bit to the user for logging and metrics, and giving insight into whether or not they are stuck in a retry loop, or e.g. why the reconnect may have failed.

@kschoche kschoche merged commit 5cee612 into master Sep 4, 2024
16 checks passed
@kschoche kschoche deleted the kyle.schochenmaier/plat-742/add_reconnect_cb_to_wsclient branch September 4, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants