From 8fd1207119cbbf994e8433b102fd12f22758a24d Mon Sep 17 00:00:00 2001 From: Borui <39862938+qiaoborui@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:13:14 +0800 Subject: [PATCH] feat: add retryInterval --- client/client.go | 2 ++ client/xclient.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/client/client.go b/client/client.go index 0fb2b2b7..d5669f23 100644 --- a/client/client.go +++ b/client/client.go @@ -161,6 +161,8 @@ type Option struct { // Retries retries to send Retries int + // RetryInterval is the interval between retries + RetryInterval time.Duration // Time to disallow the bad server not to be selected TimeToDisallow time.Duration diff --git a/client/xclient.go b/client/xclient.go index 98179e02..2b0676ef 100644 --- a/client/xclient.go +++ b/client/xclient.go @@ -582,6 +582,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface switch c.failMode { case Failtry: retries := c.option.Retries + retryInterval := c.option.RetryInterval for retries >= 0 { retries-- @@ -602,6 +603,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface c.removeClient(k, c.servicePath, serviceMethod, client) } client, e = c.getCachedClient(k, c.servicePath, serviceMethod, args) + time.Sleep(retryInterval) } if err == nil { err = e @@ -609,6 +611,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface return err case Failover: retries := c.option.Retries + retryInterval := c.option.RetryInterval for retries >= 0 { retries-- @@ -628,6 +631,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface if uncoverError(err) { c.removeClient(k, c.servicePath, serviceMethod, client) } + time.Sleep(retryInterval) // select another server k, client, e = c.selectClient(ctx, c.servicePath, serviceMethod, args) }