Skip to content

Commit cdabccf

Browse files
committed
修改健康检查, 异常和正常各自只会调用一次回调函数
1 parent a9cf501 commit cdabccf

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

client/candy.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type CandyClient struct {
4141
handler MessageHandler
4242
stream meta.Gate_ReadyClient
4343
health healthpb.HealthClient
44+
bhealth bool
4445
}
4546

4647
// NewCandyClient - create an new CandyClient
@@ -59,6 +60,8 @@ func (c *CandyClient) Start() (err error) {
5960
return
6061
}
6162

63+
c.bhealth = true
64+
6265
go c.loopRecvMessage()
6366

6467
//健康检查
@@ -360,7 +363,18 @@ func (c *CandyClient) healthCheck() {
360363

361364
_, err := c.health.Check(context.Background(), req)
362365
if err != nil {
363-
c.handler.OnUnHealth(err.Error())
366+
//确保异常只会调用一次
367+
if c.bhealth {
368+
c.bhealth = false
369+
c.handler.OnUnHealth(err.Error())
370+
}
371+
continue
372+
}
373+
374+
//由异常到正常
375+
if !c.bhealth {
376+
c.bhealth = true
377+
c.handler.OnHealth()
364378
}
365379
}
366380
}

0 commit comments

Comments
 (0)