zood/watchdog.go

43 lines
864 B
Go
Raw Normal View History

2024-11-15 09:12:08 -06:00
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 NewWatchdog() {
me.dog = time.NewTicker(me.pollDelay)
defer me.dog.Stop()
done := 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 <-done:
fmt.Println("Done!")
return
case t := <-me.dog.C:
2024-11-15 18:11:52 -06:00
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
2024-11-15 19:25:24 -06:00
updatePackages()
2024-11-15 21:51:40 -06:00
// pingStatus()
2024-11-15 20:59:42 -06:00
sendMachine()
2024-11-15 09:12:08 -06:00
// h.pollHypervisor()
// h.Scan()
}
}
}