summaryrefslogtreecommitdiff
path: root/watchdog.go
blob: 7a72a54763190396315e2787fe4e56a1181e802a (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
package main

import (
	"fmt"
	"time"

	pb "go.wit.com/lib/protobuf/virtbuf"
	"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 (h *HyperT) sendDirs() {
	url := "http://" + h.pb.Hostname + ":2520/cluster"
	var msg string
	var data []byte

	var c *pb.Cluster
	c = new(pb.Cluster)
	for _, dir := range me.cluster.Dirs {
		c.Dirs = append(c.Dirs, dir)
	}
	msg = c.FormatJSON()
	data = []byte(msg) // Convert the string to []byte
	req, err := httpPost(url, data)
	if err != nil {
		log.Info("error:", err)
		return
	}
	// log.Info("http post url:", url)
	// log.Info("http post data:", msg)

	log.Info("EVENT start droplet response: " + string(req))
}

func (h *HyperT) NewWatchdog() {
	h.dog = time.NewTicker(me.hyperPollDelay)
	defer h.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 := <-h.dog.C:
			log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t)
			// h.pollHypervisor()
			// h.Scan()
		}
	}
}