summaryrefslogtreecommitdiff
path: root/watchdog.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 09:12:08 -0600
committerJeff Carr <[email protected]>2024-11-15 09:12:08 -0600
commit7b069233955c6f35270f0cb2cb49bf6038c11020 (patch)
tree15515a666395193f7f0aebccdc6cc68573267d3a /watchdog.go
parent6c920e0925c5b9db4354c31a693140adf024d88b (diff)
add watchdog
Diffstat (limited to 'watchdog.go')
-rw-r--r--watchdog.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/watchdog.go b/watchdog.go
new file mode 100644
index 0000000..38b1959
--- /dev/null
+++ b/watchdog.go
@@ -0,0 +1,39 @@
+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:
+ log.Info("Watchdog() ticked", me.Zookeeper, "Current time: ", t)
+ // h.pollHypervisor()
+ // h.Scan()
+ }
+ }
+}