-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (41 loc) · 1.38 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
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/alexguzun/go_feed_service/domain/repository"
"github.com/alexguzun/go_feed_service/domain/services"
"github.com/alexguzun/go_feed_service/infrastructure/db"
repoImpl "github.com/alexguzun/go_feed_service/infrastructure/repository"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
log.Info("Starting")
log.SetLevel(log.DebugLevel)
var finishUP = make(chan struct{})
var gracefulStop = make(chan os.Signal)
signal.Notify(gracefulStop, os.Interrupt, syscall.SIGTERM)
signal.Notify(gracefulStop, os.Interrupt, syscall.SIGINT)
go func() {
// wait for our os signal to stop the app
// on the graceful stop channel
sig := <-gracefulStop
log.WithField("sig", sig).Debug("Caught signal")
// send message on "finish up" channel to tell the app to
// gracefully shutdown
finishUP <- struct{}{}
}()
session := db.GetMongoSession()
defer session.Close()
var feedSourceRepo repository.FeedSourceRepository = &repoImpl.FeedSourceMongoRepo{Session: session}
var feedEntriesRepo repository.FeedEntriesRepository = &repoImpl.FeedEntriesMongoRepo{Session: session}
services.Start(feedSourceRepo, feedEntriesRepo)
log.Info("Started")
// wait for finishUP channel write to close the app down
<-finishUP
log.Debug("Stopping things, might take 2 seconds")
services.Stop()
time.Sleep(2 * time.Second)
os.Exit(1)
}