diff options
| author | Jeff Carr <[email protected]> | 2024-10-30 02:28:53 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-30 02:28:53 -0500 |
| commit | 73b81913fa941504dfd2aa84fab9692b34fdcff6 (patch) | |
| tree | e63dcac97b103498428e0698f75f05eb9425f451 /watchdog.go | |
initial commitv0.0.1
Diffstat (limited to 'watchdog.go')
| -rw-r--r-- | watchdog.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/watchdog.go b/watchdog.go new file mode 100644 index 0000000..7a72a54 --- /dev/null +++ b/watchdog.go @@ -0,0 +1,63 @@ +package main + +import ( + "fmt" + "time" + + pb "go.wit.com/lib/protobuf/virtbuf" + "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 (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)) +} + +func (h *HyperT) NewWatchdog() { + h.dog = time.NewTicker(me.hyperPollDelay) + defer h.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 := <-h.dog.C: + log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t) + // h.pollHypervisor() + // h.Scan() + } + } +} |
