Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f2025ef6f | |||
| 3afe78f9e3 | |||
| eb763ed49c | |||
| 6537d79b19 | |||
| e55a2f42fe | |||
| 82d68e91b8 |
@@ -102,32 +102,33 @@ func (s *Service) Register() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (s *Service) Unregister() error {
|
func (s *Service) Unregister() error {
|
||||||
|
// s.ttlTicker.Stop()
|
||||||
|
// s.hcTicker.Stop()
|
||||||
|
|
||||||
s.client.Catalog().Deregister(&consul.CatalogDeregistration{
|
s.client.Catalog().Deregister(&consul.CatalogDeregistration{
|
||||||
Address: s.Address,
|
Address: s.Address,
|
||||||
ServiceID: s.GetID(),
|
ServiceID: s.GetID(),
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
s.ttlTicker.Stop()
|
|
||||||
|
|
||||||
return s.agent.ServiceDeregister(s.GetID())
|
return s.agent.ServiceDeregister(s.GetID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) RegisterHealthChecks() {
|
func (s *Service) RegisterHealthChecks() {
|
||||||
go func() { // startup register
|
go func() { // startup register
|
||||||
s.hcTicker = time.NewTicker(time.Second)
|
t := time.NewTicker(time.Second)
|
||||||
for range s.hcTicker.C {
|
for range t.C {
|
||||||
if ok, _ := s.healthCheck(); ok {
|
if ok, _ := s.healthCheck(); ok {
|
||||||
s.hcTicker.Stop()
|
t.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() { // TTL
|
go func() { // TTL
|
||||||
s.ttlTicker = time.NewTicker(s.ttl)
|
t := time.NewTicker(s.ttl)
|
||||||
for range s.ttlTicker.C {
|
for range t.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)
|
||||||
// s.ttlTicker.Stop()
|
t.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -157,6 +158,7 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user