File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments