fix: don't spam nodes with updates and instead pull the registry on keepalive
This commit is contained in:
parent
7fb90dd1da
commit
476c4b056f
5 changed files with 108 additions and 40 deletions
|
|
@ -92,7 +92,6 @@ func (r *Role) Leave() error {
|
|||
|
||||
func (r *Role) OnStartup(ctx context.Context) error {
|
||||
r.keepaliveGroup.Go(r.keepaliveFunc(ctx))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -107,11 +106,20 @@ func (r *Role) keepaliveFunc(ctx context.Context) func() {
|
|||
logger := log.With().Str("name", m.Hostname).Logger()
|
||||
logger.Debug().Msg("sending keepalive packet")
|
||||
|
||||
if _, err := client.Post[any](m.Endpoint, types.PathMasterKeepalive, r.state.Self); err != nil {
|
||||
nodes, err := client.Post[map[string]types.Node](m.Endpoint, types.PathMasterKeepalive, r.state.Self)
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Msg("unable to send keepalive packet")
|
||||
} else {
|
||||
logger.Debug().Msg("keepalive packet sent")
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Debug().Msg("keepalive packet sent")
|
||||
|
||||
if err := r.state.Registry.Set(*nodes); err != nil {
|
||||
logger.Warn().Err(err).Msg("unable to set masters nodes")
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,26 +135,10 @@ func (r *Role) keepaliveFunc(ctx context.Context) func() {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Role) onJoin(node types.Node) (bool, error) {
|
||||
if err := r.state.Registry.AddNode(node); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *Role) onLeave(node types.Node) (bool, error) {
|
||||
if err := r.state.Registry.RemoveNode(node); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func healthcheck() (string, error) {
|
||||
return "OK", nil
|
||||
}
|
||||
|
||||
func (n *Role) RegisterHandlers(r types.Registrator) {
|
||||
r.Register(types.GetEndpoint(types.PathNodeHealthcheck, healthcheck))
|
||||
r.Register(types.PostEndpoint(types.PathNodeJoin, n.onJoin))
|
||||
r.Register(types.PostEndpoint(types.PathNodeLeave, n.onLeave))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue