Move the start of the UniversalExecutor's consulSyncer to initialize once

This should be handled via a sync.Once primative, but I don't want to
unpack that atm.
This commit is contained in:
Sean Chittenden
2016-06-08 02:25:32 -04:00
parent 54838b9eba
commit 3052e7477a

View File

@@ -483,6 +483,7 @@ func (e *UniversalExecutor) SyncServices(ctx *ConsulContext) error {
cs.SetServiceRegPrefix(consul.GenerateServicePrefix(e.ctx.AllocID, e.ctx.Task.Name))
cs.SetAddrFinder(e.ctx.Task.FindHostAndPortFor)
e.consulSyncer = cs
go e.consulSyncer.Run()
}
if e.ctx != nil {
syncerFn := func() error {
@@ -492,7 +493,6 @@ func (e *UniversalExecutor) SyncServices(ctx *ConsulContext) error {
}
e.consulSyncer.AddPeriodicHandler(e.ctx.AllocID, syncerFn)
}
go e.consulSyncer.Run()
err := e.consulSyncer.SyncServices() // Attempt to register immediately
return err
}