Consul disvocery.go refactoring

This commit is contained in:
Piotr Biernat 2023-04-07 10:09:10 +02:00
parent 457142d8ad
commit effc7a6039

View File

@ -80,19 +80,17 @@ func (s *Service) Register() error {
go func(s *Service) { // startup register
ticker := time.NewTicker(time.Millisecond * 100)
for range ticker.C {
ok, _ := s.healthCheck()
if ok {
if ok, _ := s.healthCheck(); ok {
ticker.Stop()
}
}
}(s)
go func(s *Service) { // TTL
interval := s.ttl - time.Second*2
interval := s.ttl - time.Second*2 // 2 seconds overhead
ticker := time.NewTicker(interval)
for range ticker.C {
_, err := s.healthCheck()
if err != nil {
if _, err := s.healthCheck(); err != nil {
fmt.Printf("TTL Error: %v\n", err)
}
}