// Execute starts the file watcher and terminates it if the defined string appeared or a timeout is reached.
Execute starts the file watcher and terminates it if the defined string appeared or a timeout is reached.
// Execute starts the file watcher and terminates it if the defined string appeared or a timeout is reached .
func (watch Watch) Execute() (result model.Result) {
	fmt.Printf("Start watching \"%s\" for \"%s\" (Timeout: %ds)\n", watch.Path, watch.Message, watch.Timeout)
	watcher := make(chan error)
	go tailFile(watch.Path, watch.Message, tail.Config{Follow: true}, watcher)
	select {
	case err := <-watcher:
		if err != nil {
			fmt.Println("Message was not found")
			result.WasSuccessful = false
			result.Message = err.Error()
			return result
		}
	case <-time.After(time.Duration(watch.Timeout) * time.Second):
		result.WasSuccessful = false
		result.Message = "Timeout waiting for message"
		return result
	}
	close(watcher)
	fmt.Println("Message found")
	result.WasSuccessful = true
	result.Message = "Message found"
	return result
}
func ( watch Watch ) Execute ( ) ( result model . Result ) { fmt . Printf ( " \" \" \" \" \n " , watch . Path , watch . Message , watch . Timeout ) watcher := make ( chan error ) go tailFile ( watch . Path , watch . Message , tail . Config { Follow : true } , watcher ) select { case err := <- watcher : if err != nil { fmt . Println ( " " ) result . WasSuccessful = false result . Message = err . Error ( ) return result } case <- time . After ( time . Duration ( watch . Timeout ) * time . Second ) : result . WasSuccessful = false result . Message = " " return result } close ( watcher ) fmt . Println ( " " ) result . WasSuccessful = true result . Message = " " return result }
Execute starts the file watcher and terminates it if the defined string appeared or a timeout is reached.
Execute starts the file watcher and terminates it if the defined string appeared or a timeout is reached .
// Setup the channel we listen for the result // Tail the file in a go routine // Check for the result or timeout if it takes to long // Close the channel