Merge pull request #3 from crosbymichael/peers

Join peers in create
This commit is contained in:
Evan Hazlett 2018-09-14 17:03:21 -04:00 committed by GitHub
commit f4f89765ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -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
mc.Logger = log.New(ioutil.Discard, "", 0)
if !cfg.Debug {
mc.Logger = log.New(ioutil.Discard, "", 0)
}
host, port, err := net.SplitHostPort(cfg.ClusterAddress)
if err != nil {

View File

@ -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
}