Consul disvocery.go refactoring
This commit is contained in:
parent
457142d8ad
commit
effc7a6039
@ -80,19 +80,17 @@ func (s *Service) Register() error {
|
|||||||
go func(s *Service) { // startup register
|
go func(s *Service) { // startup register
|
||||||
ticker := time.NewTicker(time.Millisecond * 100)
|
ticker := time.NewTicker(time.Millisecond * 100)
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
ok, _ := s.healthCheck()
|
if ok, _ := s.healthCheck(); ok {
|
||||||
if ok {
|
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(s)
|
}(s)
|
||||||
|
|
||||||
go func(s *Service) { // TTL
|
go func(s *Service) { // TTL
|
||||||
interval := s.ttl - time.Second*2
|
interval := s.ttl - time.Second*2 // 2 seconds overhead
|
||||||
ticker := time.NewTicker(interval)
|
ticker := time.NewTicker(interval)
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
_, err := s.healthCheck()
|
if _, err := s.healthCheck(); err != nil {
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("TTL Error: %v\n", err)
|
fmt.Printf("TTL Error: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user