-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Realtime improvements #154
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
Conversation
* Don't panic in realtime * Retry fetching environment forever if cannot initialise * Use exponential backoff when reconnecting to SSE
client.go
Outdated
|
|
||
| c.log.Info("environment updated", "environment", env.APIKey) | ||
| c.once.Do(func() { | ||
| if c.config.useRealtime && c.realtime == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be part of this method; UpdateEnvironment doesn't need to know anything about real-time
| for { | ||
| select { | ||
| case <-ticker.C: | ||
| if !pollForever { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to real-time module/package; pollEnvironment should not be responsible for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this due to time constraints, but a complete refactor is needed.
Add WithPolling option
If
WithRealtimewas used, this also enables polling in the background. This lets us have polling as a fallback for SSERetry environment fetch on startup, don't panic in realtime
Instead of trying to fetch the environment document once and panicking from realtime if we couldn't, we now retry the initialisation indefinitely in a different goroutine. Once the environment initialises, we start the realtime connection as usual.
Retry SSE reconnections with exponential backoff + jitter
Used for error handling when SSE connection fails
Other features
slogWithSlogLoggeroption