1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Refactoring in daemon/discovery.go

Replace time.Sleep with time.Tick and remove unnecessary var block.
Use Warn log-level instead of error.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-11-09 14:03:29 -08:00
parent 143f3579b0
commit d83b5dc177

View file

@ -21,11 +21,8 @@ const (
// initDiscovery initialized the nodes discovery subsystem by connecting to the specified backend
// and start a registration loop to advertise the current node under the specified address.
func initDiscovery(backend, address string, clusterOpts map[string]string) (discovery.Backend, error) {
var (
discoveryBackend discovery.Backend
err error
)
if discoveryBackend, err = discovery.New(backend, defaultDiscoveryHeartbeat, defaultDiscoveryTTL, clusterOpts); err != nil {
discoveryBackend, err := discovery.New(backend, defaultDiscoveryHeartbeat, defaultDiscoveryTTL, clusterOpts)
if err != nil {
return nil, err
}
@ -35,14 +32,18 @@ func initDiscovery(backend, address string, clusterOpts map[string]string) (disc
return discoveryBackend, nil
}
func registerAddr(backend discovery.Backend, addr string) {
if err := backend.Register(addr); err != nil {
log.Warnf("Registering as %q in discovery failed: %v", addr, err)
}
}
// registrationLoop registers the current node against the discovery backend using the specified
// address. The function never returns, as registration against the backend comes with a TTL and
// requires regular heartbeats.
func registrationLoop(discoveryBackend discovery.Backend, address string) {
for {
if err := discoveryBackend.Register(address); err != nil {
log.Errorf("Registering as %q in discovery failed: %v", address, err)
}
time.Sleep(defaultDiscoveryHeartbeat)
registerAddr(discoveryBackend, address)
for range time.Tick(defaultDiscoveryHeartbeat) {
registerAddr(discoveryBackend, address)
}
}