From efe00d2ccd4a6ee3efc54ffd7c2042de27e996d0 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 9 Jun 2016 21:29:10 -0400 Subject: [PATCH] Update Syncer.Run() to call SyncServices(). --- command/agent/consul/syncer.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/command/agent/consul/syncer.go b/command/agent/consul/syncer.go index efd7463ee..4ade66cca 100644 --- a/command/agent/consul/syncer.go +++ b/command/agent/consul/syncer.go @@ -416,7 +416,7 @@ func (c *Syncer) deregisterCheck(ID string) error { func (c *Syncer) Run() { d := initialSyncDelay + lib.RandomStagger(initialSyncBuffer-initialSyncDelay) sync := time.NewTimer(d) - c.logger.Printf("[DEBUG] consul.sync: sleeping %v before first sync", d) + c.logger.Printf("[DEBUG] consul.syncer: sleeping %v before first sync", d) for { select { @@ -424,13 +424,17 @@ func (c *Syncer) Run() { d = syncInterval - lib.RandomStagger(syncInterval/syncJitter) sync.Reset(d) - if err := c.performSync(); err != nil { - if c.runChecks { - c.logger.Printf("[DEBUG] consul.sync: disabling checks until Consul sync completes for %q: %v", c.serviceRegPrefix, err) + if err := c.SyncServices(); err != nil { + if c.consulAvailable { + c.logger.Printf("[DEBUG] consul.syncer: disabling checks until successful sync for %q: %v", c.serviceRegPrefix, err) + } else { + c.consulAvailable = false } - c.runChecks = false } else { - c.runChecks = true + if !c.consulAvailable { + c.logger.Printf("[DEBUG] consul.syncer: re-enabling checks for for %q", c.serviceRegPrefix) + } + c.consulAvailable = true } case <-c.notifySyncCh: sync.Reset(syncInterval) @@ -462,20 +466,19 @@ func (c *Syncer) RunHandlers() error { return mErr.ErrorOrNil() } -// performSync sync the services and checks we are tracking with Consul. -func (c *Syncer) performSync() error { - var mErr multierror.Error +// SyncServices sync the services with the Consul Agent +func (c *Syncer) SyncServices() error { if err := c.RunHandlers(); err != nil { - mErr.Errors = append(mErr.Errors, err) + return err } if err := c.syncServices(); err != nil { - mErr.Errors = append(mErr.Errors, err) + return err } if err := c.syncChecks(); err != nil { - mErr.Errors = append(mErr.Errors, err) + return err } - return mErr.ErrorOrNil() + return nil } // filterConsulServices prunes out all the service whose ids are not prefixed