From 58eefb9c1785825bf07f3a7dbebd4e461fec7f9f Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Wed, 31 Oct 2018 13:30:29 +0800 Subject: [PATCH] Add TestOnBorrow check func of redis pool to verify the getting conn Signed-off-by: Steven Zou --- src/jobservice/runtime/bootstrap.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/jobservice/runtime/bootstrap.go b/src/jobservice/runtime/bootstrap.go index 70d257bfc..1f511e9f9 100644 --- a/src/jobservice/runtime/bootstrap.go +++ b/src/jobservice/runtime/bootstrap.go @@ -192,6 +192,14 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(ctx *env.Context, cfg *config.Con redis.DialWriteTimeout(dialWriteTimeout), ) }, + TestOnBorrow: func(c redis.Conn, t time.Time) error { + if time.Since(t) < time.Minute { + return nil + } + + _, err := c.Do("PING") + return err + }, } redisWorkerPool := pool.NewGoCraftWorkPool(ctx,