cleanup old code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
8ad58db1cf
commit
8a2502c61b
32
watchdog.go
32
watchdog.go
|
@ -2,36 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// scan hypervisors every i seconds
|
|
||||||
func (h *HyperT) NewWatchdog() {
|
|
||||||
var delay int = 99
|
|
||||||
var i int = delay
|
|
||||||
h.MyTicker(h.Delay, h.Hostname, func() {
|
|
||||||
i += 1
|
|
||||||
// check if the env var is set to autoscan
|
|
||||||
if os.Getenv("WATCHDOG_AUTO_SCAN") != "true" {
|
|
||||||
if i < delay {
|
|
||||||
i = delay
|
|
||||||
}
|
|
||||||
// print every 'delay' seconds
|
|
||||||
if i%delay == 0 {
|
|
||||||
log.Info("Not auto scanning", i, "WATCHDOG_AUTO_SCAN =", os.Getenv("WATCHDOG_AUTO_SCAN"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if i < delay {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
i = 0
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// timeFunction takes a function as an argument and returns the execution time.
|
// timeFunction takes a function as an argument and returns the execution time.
|
||||||
func TimeFunction(f func()) time.Duration {
|
func TimeFunction(f func()) time.Duration {
|
||||||
startTime := time.Now() // Record the start time
|
startTime := time.Now() // Record the start time
|
||||||
|
@ -39,8 +14,8 @@ func TimeFunction(f func()) time.Duration {
|
||||||
return time.Since(startTime) // Calculate the elapsed time
|
return time.Since(startTime) // Calculate the elapsed time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HyperT) MyTicker(t time.Duration, name string, f func()) {
|
func (h *HyperT) NewWatchdog() {
|
||||||
h.Dog = time.NewTicker(t)
|
h.Dog = time.NewTicker(h.Delay)
|
||||||
defer h.Dog.Stop()
|
defer h.Dog.Stop()
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
/*
|
/*
|
||||||
|
@ -56,9 +31,8 @@ func (h *HyperT) MyTicker(t time.Duration, name string, f func()) {
|
||||||
fmt.Println("Done!")
|
fmt.Println("Done!")
|
||||||
return
|
return
|
||||||
case t := <-h.Dog.C:
|
case t := <-h.Dog.C:
|
||||||
log.Log(POLL, "Watchdog() ticked", name, "Current time: ", t)
|
log.Log(POLL, "Watchdog() ticked", h.Hostname, "Current time: ", t)
|
||||||
h.Scan()
|
h.Scan()
|
||||||
// f()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue