Dont set default TTL. Stop tracking nodes with no TTL

This commit is contained in:
Milos Gajdos 2019-09-29 21:42:30 +01:00
parent 204c7d1fcf
commit 859ecb1872

View File

@ -73,8 +73,8 @@ func (m *Registry) ttlPrune() {
case <-prune.C:
m.Lock()
for nodeTrackId, node := range m.nodes {
// if we exceed the TTL threshold we need to stop tracking the node
if time.Since(node.lastSeen) > node.ttl {
// if the TTL has been set and we exceed the hresholdset by it we stop tracking the node
if node.ttl.Seconds() != 0.0 && time.Since(node.lastSeen) > node.ttl {
// split nodeTrackID into service Name, Version and Node Id
trackIdSplit := strings.Split(nodeTrackId, "+")
svcName, svcVersion, nodeId := trackIdSplit[0], trackIdSplit[1], trackIdSplit[2]
@ -183,11 +183,6 @@ func (m *Registry) Register(s *registry.Service, opts ...registry.RegisterOption
o(&options)
}
// if no TTL has been set, set it to DefaultTTL
if options.TTL.Seconds() == 0.0 {
options.TTL = DefaultTTL
}
if service, ok := m.Services[s.Name]; !ok {
m.Services[s.Name] = []*registry.Service{s}
// add all nodes into nodes map to track their TTL