2024-10-12 10:59:11 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2024-10-26 20:53:52 -05:00
|
|
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
2024-10-12 10:59:11 -05:00
|
|
|
"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-10-26 20:53:52 -05:00
|
|
|
func (h *HyperT) sendDirs() {
|
|
|
|
url := "http://" + h.pb.Hostname + ":2520/cluster"
|
|
|
|
var msg string
|
|
|
|
var data []byte
|
|
|
|
|
|
|
|
var c *pb.Cluster
|
|
|
|
c = new(pb.Cluster)
|
|
|
|
for _, dir := range me.cluster.Dirs {
|
|
|
|
c.Dirs = append(c.Dirs, dir)
|
|
|
|
}
|
|
|
|
msg = c.FormatJSON()
|
|
|
|
data = []byte(msg) // Convert the string to []byte
|
|
|
|
req, err := httpPost(url, data)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("error:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// log.Info("http post url:", url)
|
|
|
|
// log.Info("http post data:", msg)
|
|
|
|
|
|
|
|
log.Info("EVENT start droplet response: " + string(req))
|
|
|
|
}
|
|
|
|
|
2024-10-18 14:46:44 -05:00
|
|
|
func (h *HyperT) NewWatchdog() {
|
2024-10-22 19:57:49 -05:00
|
|
|
h.dog = time.NewTicker(me.delay)
|
|
|
|
defer h.dog.Stop()
|
2024-10-12 10:59:11 -05:00
|
|
|
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
|
2024-10-22 19:57:49 -05:00
|
|
|
case t := <-h.dog.C:
|
2024-10-22 17:27:24 -05:00
|
|
|
log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t)
|
2024-10-22 19:34:50 -05:00
|
|
|
h.pollHypervisor()
|
|
|
|
// h.Scan()
|
2024-10-12 10:59:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|