-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.go
67 lines (58 loc) · 1.34 KB
/
script.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
package galicia2
import (
"context"
"github.com/whitewater-guide/gorge/core"
)
type optionsGalicia2 struct{}
type scriptGalicia2 struct {
name string
listURL string
gaugeURLFormat string
core.LoggingScript
}
func (s *scriptGalicia2) ListGauges() (core.Gauges, error) {
items, err := s.parseTable()
if err != nil {
return nil, err
}
jobsCh := make(chan *core.Gauge, len(items))
resultsCh := make(chan *core.Gauge, len(items))
for w := 1; w <= 10; w++ {
go s.gaugePageWorker(jobsCh, resultsCh)
}
for i := range items {
jobsCh <- &items[i].gauge
}
close(jobsCh)
result := core.Gauges{}
for range items {
g := <-resultsCh
result = append(result, *g)
}
close(resultsCh)
return result, nil
}
func (s *scriptGalicia2) Harvest(ctx context.Context, recv chan<- *core.Measurement, errs chan<- error, codes core.StringSet, since int64) {
defer close(recv)
defer close(errs)
gauges, err := s.parseTable()
if err != nil {
errs <- err
return
}
for _, g := range gauges {
m := g.measurement
recv <- &m
}
}
func (s *scriptGalicia2) gaugePageWorker(gauges <-chan *core.Gauge, results chan<- *core.Gauge) {
for g := range gauges {
latitude, longitude, altitude := s.parseGaugePage(g.Code)
g.Location = &core.Location{
Latitude: latitude,
Longitude: longitude,
Altitude: altitude,
}
results <- g
}
}