fix: replace time.sleep() with checking logs (#899)

Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com>
This commit is contained in:
Lisca Ana-Roberta
2022-10-21 21:17:06 +03:00
committed by GitHub
parent 00e65bd32b
commit 26d982becb
5 changed files with 139 additions and 6 deletions
+22
View File
@@ -13,6 +13,7 @@ import (
"net/url"
"os"
"path"
"strings"
"time"
godigest "github.com/opencontainers/go-digest"
@@ -425,3 +426,24 @@ func UploadImage(img Image, baseURL, repo string) error {
return err
}
func ReadLogFileAndSearchString(logPath string, stringToMatch string, timeout time.Duration) (bool, error) {
ctx, cancelFunc := context.WithTimeout(context.Background(), timeout)
defer cancelFunc()
for {
select {
case <-ctx.Done():
return false, nil
default:
content, err := os.ReadFile(logPath)
if err != nil {
return false, err
}
if strings.Contains(string(content), stringToMatch) {
return true, nil
}
}
}
}