Compare commits

...

5 Commits

Author SHA1 Message Date
7f2025ef6f add debug point 2024-07-20 14:18:08 +02:00
3afe78f9e3 fix in consul discovery 2024-07-19 17:06:39 +02:00
eb763ed49c fix in consul discovery 2024-07-19 16:52:54 +02:00
6537d79b19 fix in consul discovery 2024-07-19 16:48:08 +02:00
e55a2f42fe fix in consul discovery 2024-07-19 16:45:42 +02:00

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
s.hcTicker = time.NewTicker(time.Second)
for range s.hcTicker.C {
t := time.NewTicker(time.Second)
for range t.C {
if ok, _ := s.healthCheck(); ok {
s.hcTicker.Stop()
t.Stop()
}
}
}()
go func() { // TTL
s.ttlTicker = time.NewTicker(s.ttl)
for range s.ttlTicker.C {
t := time.NewTicker(s.ttl)
for range t.C {
if _, err := s.healthCheck(); err != nil {
fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
// s.ttlTicker.Stop()
// fmt.Printf("HealthCheck endpoint not available (%s)#: %v\n", s.GetFullAddr(), err)
t.Stop()
}
}
}()
@ -158,6 +158,7 @@ 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