zookeeper/watchdog.go

62 lines
1.4 KiB
Go
Raw Normal View History

2024-11-15 18:49:52 -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
}
2024-11-15 19:24:57 -06:00
func shutdownDog() {
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
me.dogchan <- true
}()
}
2024-11-15 18:49:52 -06:00
func NewWatchdog() {
me.dog = time.NewTicker(me.pollDelay)
defer me.dog.Stop()
2024-11-15 19:24:57 -06:00
me.dogchan = make(chan bool)
2024-11-15 18:49:52 -06:00
/*
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
for {
select {
2024-11-15 19:24:57 -06:00
case <-me.dogchan:
2024-11-15 18:49:52 -06:00
fmt.Println("Done!")
return
case t := <-me.dog.C:
// log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
var counter int
loop := me.machines.SortByName()
for loop.Scan() {
m := loop.Machine()
counter += 1
zood := m.FindPackageByName("zood")
if zood == nil {
log.Info("machine", m.Hostname, "does not have zood installed")
} else {
// log.Info("know about machine", m.Hostname, "zood version", zood.Version)
}
}
log.Info("zookeeper has", counter, "machines. Current time:", t)
2024-11-15 18:49:52 -06:00
// h.pollHypervisor()
// h.Scan()
}
}
}