Compare commits

..

No commits in common. "7f2025ef6ffe36059b39243bc306a56f9416c42f" and "82d68e91b85c8ab7816896dd59df18fb63fe49b3" have entirely different histories.

View File

@ -102,8 +102,8 @@ func (s *Service) Register() error {
return nil
}
func (s *Service) Unregister() error {
// s.ttlTicker.Stop()
// s.hcTicker.Stop()
s.ttlTicker.Stop()
s.hcTicker.Stop()
s.client.Catalog().Deregister(&consul.CatalogDeregistration{
Address: s.Address,
@ -115,20 +115,20 @@ func (s *Service) Unregister() error {
func (s *Service) RegisterHealthChecks() {
go func() { // startup register
t := time.NewTicker(time.Second)
for range t.C {
s.hcTicker = time.NewTicker(time.Second)
for range s.hcTicker.C {
if ok, _ := s.healthCheck(); ok {
t.Stop()
s.hcTicker.Stop()
}
}
}()
go func() { // TTL
t := time.NewTicker(s.ttl)
for range t.C {
s.ttlTicker = time.NewTicker(s.ttl)
for range s.ttlTicker.C {
if _, err := s.healthCheck(); err != nil {
// fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
t.Stop()
fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
// s.ttlTicker.Stop()
}
}
}()
@ -158,7 +158,6 @@ func (s *Service) healthCheck() (bool, error) {
alive := func() bool {
client := &http.Client{}
healthUrl := fmt.Sprintf("%s%s?name=%s", s.GetFullAddr(), "health", s.Name)
fmt.Printf("HealthCheck URL: %s%s?name=%s", s.GetFullAddr(), "health", s.Name)
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
if err != nil {
return false