-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (50 loc) · 1.4 KB
/
main.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
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/AsynkronIT/protoactor-go/actor"
"github.com/ansrivas/fwatcher/db"
conf "github.com/ansrivas/fwatcher/internal"
"github.com/ansrivas/fwatcher/workers"
flag "github.com/spf13/pflag"
)
var configPath string
func init() {
flag.StringVar(&configPath, "config", "", "path to a configuration file")
}
func main() {
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if configPath == "" {
log.Fatalf("No config file provided... ")
}
config, err := conf.GetConfig(configPath)
if err != nil {
log.Fatalf(err.Error())
}
hosts := config.GetString("kafka.hosts")
dirToWatch := config.GetString("app.dir")
allowedExtensions := config.GetStringSlice("app.filetypes")
log.Println(hosts, dirToWatch)
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, syscall.SIGINT, syscall.SIGTERM)
backoffWindow := time.Duration(time.Second * 10)
initialBackoff := time.Duration(time.Second * 3)
supervisor := actor.NewExponentialBackoffStrategy(backoffWindow, initialBackoff)
props := actor.
FromInstance(&workers.CoordinatorActor{BootStrapServers: hosts}).
WithSupervisor(supervisor)
pid := actor.Spawn(props)
db.NewDb()
go watchDirectory(ctx, dirToWatch, allowedExtensions, pid)
<-sigchan
cancel()
pid.Stop()
fmt.Printf("Terminating the program successfully\n")
}