blob: beb1e30bf8ec82729922ec4361c468d223390c4e (
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
|
// 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"
"os"
"time"
"go.wit.com/lib/debian"
"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
}
// sends updates to zookeeper
func zood() {
me.dog = time.NewTicker(me.pollDelay)
defer me.dog.Stop()
done := make(chan bool)
for {
select {
case <-done:
fmt.Println("Done!")
return
case _ = <-me.dog.C:
err := debian.UpdatePackages(me.machine)
if err != nil {
log.Info("UpdatePackages err", err)
me.failcount += 1
}
err = sendMachine(me.machine)
if err != nil {
log.Info("sendMachine err", err)
me.failcount += 1
}
if me.failcount > 20 {
os.Exit(0)
}
}
}
/*
// this example would exit/destroy the ticker in 10 seconds
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
*/
}
|