healthCheck 健康检查
()
| 354 | |
| 355 | // healthCheck 健康检查 |
| 356 | func (c *CandyClient) healthCheck() { |
| 357 | for !c.stop { |
| 358 | time.Sleep(time.Second) |
| 359 | req := &healthpb.HealthCheckRequest{ |
| 360 | Service: "", |
| 361 | } |
| 362 | |
| 363 | _, err := c.health.Check(context.Background(), req) |
| 364 | if err != nil { |
| 365 | //确保异常只会调用一次 |
| 366 | if c.bhealth { |
| 367 | c.bhealth = false |
| 368 | c.handler.OnUnHealth(err.Error()) |
| 369 | } |
| 370 | continue |
| 371 | } |
| 372 | |
| 373 | //由异常到正常 |
| 374 | if !c.bhealth { |
| 375 | c.bhealth = true |
| 376 | c.handler.OnHealth() |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Heartbeat 向服务器发送心跳信息 |
| 382 | func (c *CandyClient) Heartbeat() error { |
no test coverage detected