-
Notifications
You must be signed in to change notification settings - Fork 2
/
dr-feeder.go
77 lines (61 loc) · 1.46 KB
/
dr-feeder.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
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"path"
"time"
"github.com/hguandl/dr-feeder/v2/common"
"github.com/hguandl/dr-feeder/v2/notifier"
"github.com/hguandl/dr-feeder/v2/watcher"
)
// Version is current `git describe --tags` infomation.
var Version string = "v2.3.5"
func consume(ch chan common.NotifyPayload, notifiers []notifier.Notifier) {
for {
pl := <-ch
log.Printf("Received: %v\n", pl)
for _, ntf := range notifiers {
go ntf.Push(pl)
}
}
}
func watch(watcher watcher.Watcher, ch chan common.NotifyPayload) {
for {
waitSec := rand.Intn(6) + 6
watcher.Produce(ch)
time.Sleep(time.Duration(waitSec) * time.Second)
}
}
func main() {
printVersion := flag.Bool("V", false, "Print current version")
debugMode := flag.Bool("d", false, "Debug with fake server")
pathPtr := flag.String("c", ".", "Configuration and data directory")
flag.Parse()
if *printVersion {
fmt.Printf("dr-feeder %s\n", Version)
return
}
if *debugMode {
println("Running on debug mode...")
}
config, err := LoadConfig(path.Join(*pathPtr, "config.yaml"))
if err != nil {
log.Fatal(err)
}
notifiers, err := notifier.ParseNotifiers(config.Notifiers)
if err != nil {
log.Fatal(err)
}
watchers, err := watcher.ParseWatchers(config.Watchers, *pathPtr, *debugMode)
if err != nil {
log.Fatal(err)
}
ch := make(chan common.NotifyPayload)
for _, watcher := range watchers {
go watch(watcher, ch)
}
go consume(ch, notifiers)
select {}
}