-
Notifications
You must be signed in to change notification settings - Fork 3
/
check.go
78 lines (62 loc) · 1.48 KB
/
check.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"log"
"github.com/pkg/errors"
)
func runCheck() error {
if metricsListenAddress != nil {
go startMetrics()
}
// read domain list
if err := checker.ReadDomains(*domains); err != nil {
return errors.Wrap(err, "unable to read domain list")
}
if err := checker.Start(); err != nil {
return errors.Wrap(err, "unable to start checker")
}
// Start result writer
finishedWg.Add(1)
go resultWriter()
createJobs()
checker.Stop()
finishedWg.Wait()
return nil
}
func createJobs() {
id := 0
batchSize := 1000
found := batchSize
for batchSize == found {
// Read the next batch
rows, err := dbConn.Query("SELECT id, ip FROM nameservers WHERE id > ? LIMIT ?", id, batchSize)
if err != nil {
log.Fatalf("select batch failed: %v", err)
}
found = 0
for rows.Next() {
var address string
// get RawBytes from data
err = rows.Scan(&id, &address)
if err != nil {
log.Fatalf("scanning DB values failed: %v", err)
}
checker.Enqueue(id, address)
found++
}
rows.Close()
}
}
func resultWriter() {
stm, err := dbConn.Prepare("UPDATE nameservers SET name=?, state=?, error=?, version=?, dnssec=?, checked_at=NOW(), country_id=?, city=? WHERE id=?")
if err != nil {
log.Fatalf("prepare statement failed: %v", err)
}
defer stm.Close()
for res := range checker.Results() {
if *debug {
log.Println(res)
}
stm.Exec(res.Name, res.State, res.Err, res.Version, res.Dnssec, res.Country, res.City, res.ID)
}
finishedWg.Done()
}