mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
21 lines
368 B
Go
21 lines
368 B
Go
package util
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
)
|
|
|
|
func Retry(name string, waitTimeLimit time.Duration, job func() error) (err error) {
|
|
waitTime := time.Second
|
|
for waitTime < waitTimeLimit {
|
|
err = job()
|
|
if err == nil {
|
|
break
|
|
}
|
|
glog.V(1).Infof("retry %s", name)
|
|
time.Sleep(waitTime)
|
|
waitTime += waitTime / 2
|
|
}
|
|
return err
|
|
} |