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