We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7e608fa commit 6bebf90Copy full SHA for 6bebf90
pkg/utils/file.go
@@ -3,8 +3,10 @@ package utils
3
import (
4
"bytes"
5
"errors"
6
+ "fmt"
7
"os"
8
"strconv"
9
+ "time"
10
)
11
12
func ReadPidFile(pidFile string) (int, error) {
@@ -35,3 +37,17 @@ func FileExists(path string) (bool, error) {
35
37
}
36
38
return exists, err
39
40
+
41
+// WaitForFileWithBackoffs attempts to discover a file in maxBackoffs attempts
42
+func WaitForFileWithBackoffs(maxBackoffs int, backoff time.Duration, path string) error {
43
+ backoffWait := backoff
44
+ for i := 0; i < maxBackoffs; i++ {
45
+ e, _ := FileExists(path)
46
+ if e {
47
+ return nil
48
+ }
49
+ time.Sleep(backoffWait)
50
+ backoffWait *= 2
51
52
+ return fmt.Errorf("unable to find file at %q", path)
53
+}
0 commit comments