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 AdvertiseAddress string
// Peers is a local cache of peer members // Peers is a local cache of peer members
Peers []string Peers []string
// Debug output for memberlist
Debug bool
} }
func (a *Agent) Config() *Config { 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.Delegate = NewAgentDelegate(cfg.NodeName, cfg.Address, peerUpdateChan, nodeEventChan)
mc.Events = NewEventHandler(nodeEventChan) mc.Events = NewEventHandler(nodeEventChan)
// disable logging for memberlist if !cfg.Debug {
// TODO: enable if debug mc.Logger = log.New(ioutil.Discard, "", 0)
mc.Logger = log.New(ioutil.Discard, "", 0) }
host, port, err := net.SplitHostPort(cfg.ClusterAddress) host, port, err := net.SplitHostPort(cfg.ClusterAddress)
if err != nil { if err != nil {

View file

@ -7,7 +7,7 @@ import (
) )
// Start handles cluster events // Start handles cluster events
func (a *Agent) Start(s chan os.Signal) { func (a *Agent) Start(s chan os.Signal) error {
go func() { go func() {
for range a.peerUpdateChan { for range a.peerUpdateChan {
if err := a.members.UpdateNode(nodeUpdateTimeout); err != nil { 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
} }