zookeeper/watchdog.go

48 lines
983 B
Go

package main
import (
"fmt"
"time"
"go.wit.com/log"
)
// timeFunction takes a function as an argument and returns the execution time.
func TimeFunction(f func()) time.Duration {
startTime := time.Now() // Record the start time
f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func shutdownDog() {
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
me.dogchan <- true
}()
}
func NewWatchdog() {
me.dog = time.NewTicker(me.pollDelay)
defer me.dog.Stop()
me.dogchan = make(chan bool)
/*
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
case <-me.dogchan:
fmt.Println("Done!")
return
case t := <-me.dog.C:
log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
// h.pollHypervisor()
// h.Scan()
}
}
}