Skip to content

Commit 8fd1207

Browse files
committed
feat: add retryInterval
1 parent 2f9a712 commit 8fd1207

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

โ€Žclient/client.go

+2
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

+4
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)