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:
parent
143f3579b0
commit
d83b5dc177
1 changed files with 11 additions and 10 deletions
|
@ -21,11 +21,8 @@ const (
|
||||||
// initDiscovery initialized the nodes discovery subsystem by connecting to the specified backend
|
// 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.
|
// 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) {
|
func initDiscovery(backend, address string, clusterOpts map[string]string) (discovery.Backend, error) {
|
||||||
var (
|
discoveryBackend, err := discovery.New(backend, defaultDiscoveryHeartbeat, defaultDiscoveryTTL, clusterOpts)
|
||||||
discoveryBackend discovery.Backend
|
if err != nil {
|
||||||
err error
|
|
||||||
)
|
|
||||||
if discoveryBackend, err = discovery.New(backend, defaultDiscoveryHeartbeat, defaultDiscoveryTTL, clusterOpts); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +32,18 @@ func initDiscovery(backend, address string, clusterOpts map[string]string) (disc
|
||||||
return discoveryBackend, nil
|
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
|
// 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
|
// address. The function never returns, as registration against the backend comes with a TTL and
|
||||||
// requires regular heartbeats.
|
// requires regular heartbeats.
|
||||||
func registrationLoop(discoveryBackend discovery.Backend, address string) {
|
func registrationLoop(discoveryBackend discovery.Backend, address string) {
|
||||||
for {
|
registerAddr(discoveryBackend, address)
|
||||||
if err := discoveryBackend.Register(address); err != nil {
|
for range time.Tick(defaultDiscoveryHeartbeat) {
|
||||||
log.Errorf("Registering as %q in discovery failed: %v", address, err)
|
registerAddr(discoveryBackend, address)
|
||||||
}
|
|
||||||
time.Sleep(defaultDiscoveryHeartbeat)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue