diff options
| author | Jeff Carr <[email protected]> | 2024-11-15 18:49:52 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-15 18:49:52 -0600 |
| commit | fbd638aec099fc88c5bd616dff891bb942d2de4b (patch) | |
| tree | 0f3a8abb3e61ec3261f5db803fb561e2c221e04c /watchdog.go | |
day 1.v0.0.1
Diffstat (limited to 'watchdog.go')
| -rw-r--r-- | watchdog.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/watchdog.go b/watchdog.go new file mode 100644 index 0000000..d70ccbf --- /dev/null +++ b/watchdog.go @@ -0,0 +1,40 @@ +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) + updatePackages() + // h.pollHypervisor() + // h.Scan() + } + } +} |
