-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
50 lines (39 loc) · 984 Bytes
/
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/akornatskyy/scheduler/core"
"github.com/akornatskyy/scheduler/domain"
"github.com/akornatskyy/scheduler/infrastructure/cron"
"github.com/akornatskyy/scheduler/infrastructure/http"
"github.com/akornatskyy/scheduler/infrastructure/postgres"
)
func main() {
log.Printf("starting scheduler version %s...", domain.Version)
dsn := os.Getenv("DSN")
service := &core.Service{
Repository: postgres.NewRepository(dsn),
Scheduler: cron.New(),
Runners: map[string]domain.Runner{
"HTTP": http.NewRunner(),
},
}
subscriber := postgres.NewSubscriber(dsn)
subscriber.SetCallback(service.OnUpdateEvent)
server := &http.Server{
Service: service,
}
service.Start()
subscriber.Start()
server.Start()
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
log.Println("shutting down...")
server.Stop()
subscriber.Stop()
service.Stop()
log.Println("done")
}