[skip ci]Add retry comment (#8776)

Signed-off-by: godchen <qingxiang.chen@zilliz.com>
pull/8799/head
godchen 2021-09-28 20:44:03 +08:00 committed by GitHub
parent 7c2729916b
commit e236a1ccf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -27,14 +27,17 @@ func newDefaultConfig() *config {
}
}
// Option is used to config the retry function.
type Option func(*config)
// Attempts is used to config the max retry times.
func Attempts(attempts uint) Option {
return func(c *config) {
c.attempts = attempts
}
}
// Sleep is used to config the initial interval time of each execution.
func Sleep(sleep time.Duration) Option {
return func(c *config) {
c.sleep = sleep
@ -45,6 +48,7 @@ func Sleep(sleep time.Duration) Option {
}
}
// MaxSleep is used to config the max interval time of each execution.
func MaxSleepTime(maxSleepTime time.Duration) Option {
return func(c *config) {
// ensure max retry interval is always larger than retry interval

View File

@ -18,6 +18,9 @@ import (
"time"
)
// Do will run function with retry mechanism.
// fn is the func to run.
// Option can control the retry times and timeout.
func Do(ctx context.Context, fn func() error, opts ...Option) error {
c := newDefaultConfig()
@ -79,6 +82,7 @@ func Unrecoverable(err error) error {
return unrecoverableError{err}
}
// IsUncoverable is used to judge whether the error is wrapped by unrecoverableError.
func IsUncoverable(err error) bool {
_, isUnrecoverable := err.(unrecoverableError)
return isUnrecoverable