Compare commits
5 Commits
82d68e91b8
...
7f2025ef6f
Author | SHA1 | Date | |
---|---|---|---|
7f2025ef6f | |||
3afe78f9e3 | |||
eb763ed49c | |||
6537d79b19 | |||
e55a2f42fe |
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user