Skip to content

Commit ac599ab

Browse files
committed
fix
1 parent 1945b48 commit ac599ab

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/util/util.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"regexp"
2424
"strings"
2525
"sync"
26+
"time"
2627

2728
"github.com/go-ini/ini"
2829
"github.com/pkg/errors"
@@ -341,3 +342,30 @@ func GetKubeClient(kubeconfig string, kubeAPIQPS float64, kubeAPIBurst int, user
341342
kubeCfg.UserAgent = userAgent
342343
return kubernetes.NewForConfig(kubeCfg)
343344
}
345+
346+
// ExecFunc returns a exec function's output and error
347+
type ExecFunc func() (err error)
348+
349+
// TimeoutFunc returns output and error if an ExecFunc timeout
350+
type TimeoutFunc func() (err error)
351+
352+
// WaitUntilTimeout waits for the exec function to complete or return timeout error
353+
func WaitUntilTimeout(timeout time.Duration, execFunc ExecFunc, timeoutFunc TimeoutFunc) error {
354+
// Create a channel to receive the result of the azcopy exec function
355+
done := make(chan bool)
356+
var err error
357+
358+
// Start the azcopy exec function in a goroutine
359+
go func() {
360+
err = execFunc()
361+
done <- true
362+
}()
363+
364+
// Wait for the function to complete or time out
365+
select {
366+
case <-done:
367+
return err
368+
case <-time.After(timeout):
369+
return timeoutFunc()
370+
}
371+
}

0 commit comments

Comments
 (0)