commit
f4f89765ea
2 changed files with 12 additions and 4 deletions
|
@ -35,6 +35,8 @@ type Config struct {
|
|||
AdvertiseAddress string
|
||||
// Peers is a local cache of peer members
|
||||
Peers []string
|
||||
// Debug output for memberlist
|
||||
Debug bool
|
||||
}
|
||||
|
||||
func (a *Agent) Config() *Config {
|
||||
|
@ -58,9 +60,9 @@ func (cfg *Config) memberListConfig(peerUpdateChan chan bool, nodeEventChan chan
|
|||
mc.Delegate = NewAgentDelegate(cfg.NodeName, cfg.Address, peerUpdateChan, nodeEventChan)
|
||||
mc.Events = NewEventHandler(nodeEventChan)
|
||||
|
||||
// disable logging for memberlist
|
||||
// TODO: enable if debug
|
||||
if !cfg.Debug {
|
||||
mc.Logger = log.New(ioutil.Discard, "", 0)
|
||||
}
|
||||
|
||||
host, port, err := net.SplitHostPort(cfg.ClusterAddress)
|
||||
if err != nil {
|
||||
|
|
8
start.go
8
start.go
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
// Start handles cluster events
|
||||
func (a *Agent) Start(s chan os.Signal) {
|
||||
func (a *Agent) Start(s chan os.Signal) error {
|
||||
go func() {
|
||||
for range a.peerUpdateChan {
|
||||
if err := a.members.UpdateNode(nodeUpdateTimeout); err != nil {
|
||||
|
@ -15,4 +15,10 @@ func (a *Agent) Start(s chan os.Signal) {
|
|||
}
|
||||
}
|
||||
}()
|
||||
if len(a.config.Peers) > 0 {
|
||||
if _, err := a.members.Join(a.config.Peers); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue