Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExponentialBackoffRetryStrategy ¶
type ExponentialBackoffRetryStrategy struct {
// contains filtered or unexported fields
}
ExponentialBackoffRetryStrategy 指数退避重试
func NewExponentialBackoffRetryStrategy ¶
func NewExponentialBackoffRetryStrategy(initialInterval, maxInterval time.Duration, maxRetries int32) (*ExponentialBackoffRetryStrategy, error)
func (*ExponentialBackoffRetryStrategy) Next ¶
func (s *ExponentialBackoffRetryStrategy) Next() (time.Duration, bool)
Example ¶
// 注意,因为在例子里面我们设置初始的重试间隔是 1s,最大重试间隔是 5s // 所以在前面四次,重试间隔都是在增长的,每次变为原来的2倍。 // 在触及到了最大重试间隔之后,就一直以最大重试间隔来重试。 retry, err := NewExponentialBackoffRetryStrategy(time.Second, time.Second*5, 10) if err != nil { fmt.Println(err) return } interval, ok := retry.Next() for ok { fmt.Println(interval) interval, ok = retry.Next() }
Output: 1s 2s 4s 5s 5s 5s 5s 5s 5s 5s
type FixedIntervalRetryStrategy ¶
type FixedIntervalRetryStrategy struct {
// contains filtered or unexported fields
}
FixedIntervalRetryStrategy 等间隔重试
func NewFixedIntervalRetryStrategy ¶
func NewFixedIntervalRetryStrategy(interval time.Duration, maxRetries int32) (*FixedIntervalRetryStrategy, error)
func (*FixedIntervalRetryStrategy) Next ¶
func (s *FixedIntervalRetryStrategy) Next() (time.Duration, bool)
Example ¶
retry, err := NewFixedIntervalRetryStrategy(time.Second, 3) if err != nil { fmt.Println(err) return } interval, ok := retry.Next() for ok { fmt.Println(interval) interval, ok = retry.Next() }
Output: 1s 1s 1s
Click to show internal directories.
Click to hide internal directories.