-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtimer.go
42 lines (37 loc) · 985 Bytes
/
timer.go
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
package main
import (
"fmt"
"time"
)
type schedulers []*time.Ticker
func (obj Domain) schedule() *time.Ticker {
if debug {
fmt.Printf("Schueduler starterd for %s:%s\n", obj.Name, time.Duration(obj.Interval)*time.Second)
}
//ticker := time.NewTicker(5 * time.Second)
ticker := time.NewTicker(time.Duration(obj.Interval) * time.Second)
go func() {
first_resolution, second_resolution := "", ""
for ; true; <-ticker.C {
temp_resolution, err := obj.Lookup()
if err == nil {
second_resolution = temp_resolution
if debug {
fmt.Printf("%v %v ", obj.Name, temp_resolution)
}
if first_resolution != second_resolution {
if debug {
fmt.Printf("Addr changed\n")
}
obj.Iptables(first_resolution, second_resolution)
first_resolution = second_resolution
} else if debug {
fmt.Printf("Addr same \n")
}
} else {
fmt.Printf("Error while querying host \"%s\": %s\n", obj.Name, err)
}
}
}()
return ticker
}