mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-28 05:15:00 +08: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
|
||
|
}
|