zood/watchdog.go

50 lines
1.0 KiB
Go
Raw Permalink Normal View History

2025-02-15 12:30:07 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
2024-11-15 09:12:08 -06:00
package main
import (
"fmt"
2024-11-18 20:22:12 -06:00
"os"
2024-11-15 09:12:08 -06:00
"time"
)
// 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 _ = <-me.dog.C:
// log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
2025-02-15 12:16:27 -06:00
s := me.forge.Machine.UpdatePackages()
2024-11-15 21:51:40 -06:00
// pingStatus()
2024-11-18 20:22:12 -06:00
me.failcount += 1
sendMachine(s)
2024-11-18 20:22:12 -06:00
if me.failcount > 20 {
os.Exit(0)
}
2024-11-15 09:12:08 -06:00
// h.pollHypervisor()
// h.Scan()
}
}
}