Skip to content

Commit

Permalink
Merge pull request #879 from qiaoborui/feat/add-retry-interval
Browse files Browse the repository at this point in the history
feat: add retry Interval
  • Loading branch information
smallnest authored Nov 22, 2024
2 parents 2f9a712 + 8fd1207 commit 3166865
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions client/xclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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--

Expand All @@ -602,13 +603,15 @@ 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
}
return err
case Failover:
retries := c.option.Retries
retryInterval := c.option.RetryInterval
for retries >= 0 {
retries--

Expand All @@ -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)
}
Expand Down

0 comments on commit 3166865

Please sign in to comment.