-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
morph: support reloading morph endpoints with SIGHUP
Add a new function `Client.Reload` that passes the `WithEndpoints` option and updates the `Client` endpoints. Closes the current connection and attempts to reconnect if there is no endpoint in the config to which the client is connected. Node service can be interrupted in this case. Add docs. Closes #1871. Signed-off-by: Andrey Butusov <andrey@nspcc.io>
- Loading branch information
Showing
6 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package client | ||
|
||
import "slices" | ||
|
||
// Reload allows runtime reconfiguration for WithEndpoints parameter. | ||
func (c *Client) Reload(opts ...Option) { | ||
cfg := new(cfg) | ||
for _, o := range opts { | ||
o(cfg) | ||
} | ||
|
||
c.cfg.endpointsLock.Lock() | ||
|
||
c.cfg.endpoints = cfg.endpoints | ||
|
||
c.cfg.endpointsLock.Unlock() | ||
|
||
conn := c.conn.Load() | ||
if conn == nil { | ||
return | ||
} | ||
|
||
// Close current connection and attempt to reconnect, if there is no endpoint | ||
// in the config to which the client is connected. | ||
// Node service can be interrupted in this case. | ||
if slices.Contains(cfg.endpoints, conn.client.Endpoint()) { | ||
conn.client.Close() | ||
} | ||
} |