Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExponentialBackoffRetryPolicy ¶
type ExponentialBackoffRetryPolicy struct { BaseWaitTime time.Duration // 基础等待时间 MaxAttempts int // 最大重试次数 }
ExponentialBackoffRetryPolicy 是一个基于指数退避的重试策略
func (*ExponentialBackoffRetryPolicy) ShouldRetry ¶
func (p *ExponentialBackoffRetryPolicy) ShouldRetry(attempt int, _ error) bool
ShouldRetry 返回true如果尝试次数小于MaxAttempts
func (*ExponentialBackoffRetryPolicy) WaitDuration ¶
func (p *ExponentialBackoffRetryPolicy) WaitDuration(attempt int) int
WaitDuration 返回等待时间,单位为秒,随着尝试次数增加而增加
type NoRetryPolicy ¶
type NoRetryPolicy struct{}
NoRetryPolicy 不重试策略
func (*NoRetryPolicy) ShouldRetry ¶
func (np *NoRetryPolicy) ShouldRetry(_ int, _ error) bool
func (*NoRetryPolicy) WaitDuration ¶
func (np *NoRetryPolicy) WaitDuration(_ int) int
type RetryPolicy ¶
type RetryPolicy interface { // ShouldRetry 决定给定的尝试次数和遇到的错误是否应该重试 ShouldRetry(attempt int, err error) bool // WaitDuration 返回给定尝试次数后,应该等待多久再进行重试 WaitDuration(attempt int) int }
RetryPolicy 定义重试策略的接口
type SimpleRetryPolicy ¶
SimpleRetryPolicy 是一个基于固定时间间隔和最大尝试次数的简单重试策略
func (*SimpleRetryPolicy) ShouldRetry ¶
func (p *SimpleRetryPolicy) ShouldRetry(attempt int, _ error) bool
ShouldRetry 返回true如果尝试次数小于MaxAttempts
func (*SimpleRetryPolicy) WaitDuration ¶
func (p *SimpleRetryPolicy) WaitDuration(_ int) int
WaitDuration 返回等待时间,单位为秒
Click to show internal directories.
Click to hide internal directories.