-
Notifications
You must be signed in to change notification settings - Fork 13
/
crabby.go
62 lines (47 loc) · 1.11 KB
/
crabby.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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"sync"
"syscall"
)
func main() {
var err error
var wg sync.WaitGroup
sigs := make(chan os.Signal, 1)
done := make(chan struct{}, 1)
cfgFile := flag.String("config", "config.yaml", "Path to config file (default: ./config.yaml)")
flag.Parse()
c, err := NewConfig(cfgFile)
if err != nil {
log.Fatalln("Error reading config file. Did you pass the -config flag? Run with -h for help.\n", err)
}
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
s, err := NewStorage(ctx, &wg, c)
if err != nil {
log.Fatalln(err)
}
// If configured, start a goroutine to report internal metrics from the Go runtime
if c.General.ReportInternalMetrics {
go startInternalMetrics(ctx, &wg, s, c.General.InternalMetricsInterval)
}
jm, err := NewJobManager(ctx, &wg, s, c)
if err != nil {
log.Fatalln("error starting job manager:", err)
}
jm.Run()
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func(cancel context.CancelFunc) {
<-sigs
cancel()
close(done)
}(cancel)
<-done
wg.Wait()
fmt.Println("Exiting!")
}