-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear.go
36 lines (29 loc) · 1.02 KB
/
linear.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package goretry
import "time"
/* Linear performs retry function with linearly incremental backoff time.
It will wait for firstWaiting to do the first retry, and then increase the waiting time by incrementStep for each next retry*/
func Linear(backoff, incrementStep time.Duration, action func() error) {
std.Linear(backoff, incrementStep, action)
}
/* Linear performs retry function with linearly incremental backoff time.
It will wait for firstWaiting to do the first retry, and then increase the waiting time by incrementStep for each next retry*/
func (i *Instance) Linear(backoff, incrementStep time.Duration, action func() error) {
var count int64
var totalWaiting time.Duration
for {
i.log("do action()")
if err := action(); err == nil {
return
}
count++
if i.MaxStopRetries != NoLimit && count >= i.MaxStopRetries {
break
}
if i.MaxStopTotalWaiting != NoDuration && totalWaiting >= i.MaxStopTotalWaiting {
break
}
backoff = i.sleep(backoff)
backoff += incrementStep
totalWaiting += backoff
}
}