Skip to content

Commit

Permalink
Implement wait_for file
Browse files Browse the repository at this point in the history
  • Loading branch information
mizzy committed Nov 17, 2016
1 parent 669149c commit df7abcf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/task/wait_for.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"os"
"strconv"
"time"

Expand Down Expand Up @@ -77,6 +78,31 @@ func connected(host string, port int) bool {
}

func (w *WaitFor) waitForFile(t *Task) {
log.Infof("[%s] wait_for: file %s %s", t.Name, w.File, w.State)
if w.State == "ready" || w.State == "present" {
for {
if isExist(w.File) {
return
} else {
time.Sleep(10 * time.Millisecond)
}
}
}

if w.State == "unready" || w.State == "absent" {
for {
if !isExist(w.File) {
return
} else {
time.Sleep(10 * time.Millisecond)
}
}
}
}

func isExist(file string) bool {
_, err := os.Stat(file)
return err == nil
}

func (w *WaitFor) validate() error {
Expand Down

0 comments on commit df7abcf

Please sign in to comment.