blob: fbbe6daa9b396edc6475656799f0c031b0c234a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  | 
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
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 shutdownDog() {
	// this example would exit/destroy the ticker in 10 seconds
	go func() {
		time.Sleep(10 * time.Second)
		me.dogchan <- true
	}()
}
func NewWatchdog() {
	me.dog = time.NewTicker(me.pollDelay)
	defer me.dog.Stop()
	me.dogchan = 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 <-me.dogchan:
			fmt.Println("Done!")
			return
		case t := <-me.dog.C:
			// log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
			var counter int
			loop := me.machines.SortByHostname()
			for loop.Scan() {
				m := loop.Next()
				counter += 1
				zood, _ := m.Packages.FindByPackageName("zood")
				if zood == nil {
					log.Info("machine", m.Hostname, "does not have zood installed")
				} else {
					// log.Info("know about machine", m.Hostname, "zood version", zood.Version)
				}
			}
			log.Info("hour watchdog:", counter, "machines. Current time:", t)
			// h.pollHypervisor()
			// h.Scan()
		}
	}
}
  |