Skip to content

Commit 3166865

Browse files
authored
Merge pull request smallnest#879 from qiaoborui/feat/add-retry-interval
feat: add retry Interval
2 parents 2f9a712 + 8fd1207 commit 3166865

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

โ€Žclient/client.goโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ type Option struct {
161161

162162
// Retries retries to send
163163
Retries int
164+
// RetryInterval is the interval between retries
165+
RetryInterval time.Duration
164166
// Time to disallow the bad server not to be selected
165167
TimeToDisallow time.Duration
166168

โ€Žclient/xclient.goโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
582582
switch c.failMode {
583583
case Failtry:
584584
retries := c.option.Retries
585+
retryInterval := c.option.RetryInterval
585586
for retries >= 0 {
586587
retries--
587588

@@ -602,13 +603,15 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
602603
c.removeClient(k, c.servicePath, serviceMethod, client)
603604
}
604605
client, e = c.getCachedClient(k, c.servicePath, serviceMethod, args)
606+
time.Sleep(retryInterval)
605607
}
606608
if err == nil {
607609
err = e
608610
}
609611
return err
610612
case Failover:
611613
retries := c.option.Retries
614+
retryInterval := c.option.RetryInterval
612615
for retries >= 0 {
613616
retries--
614617

@@ -628,6 +631,7 @@ func (c *xClient) Call(ctx context.Context, serviceMethod string, args interface
628631
if uncoverError(err) {
629632
c.removeClient(k, c.servicePath, serviceMethod, client)
630633
}
634+
time.Sleep(retryInterval)
631635
// select another server
632636
k, client, e = c.selectClient(ctx, c.servicePath, serviceMethod, args)
633637
}

0 commit comments

Comments
ย (0)