mirror of https://github.com/milvus-io/milvus.git
[skip ci]Add retry comment (#8776)
Signed-off-by: godchen <qingxiang.chen@zilliz.com>pull/8799/head
parent
7c2729916b
commit
e236a1ccf9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue