Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retry Interval #879

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading