-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainerlib.go
45 lines (38 loc) · 983 Bytes
/
containerlib.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
package containerlib
import (
"github.com/resource-aware-jds/container-lib/di"
"github.com/resource-aware-jds/container-lib/facade"
"github.com/sirupsen/logrus"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
)
func Run(workerHandlerFunc facade.ContainerHandlerFunction) {
app, cleanup, err := di.InitializeApplication(workerHandlerFunc)
if err != nil {
cleanup()
panic(err)
}
if app.Config.Debug {
// Start the pprof debug server
go func() {
err := http.ListenAndServe(app.Config.ProfilingToolsListeningURL, nil)
if err != nil {
logrus.Warn(err)
}
}()
}
app.GRPCServer.Serve()
app.TaskRunnerSvc.Run()
// Gracefully Shutdown
// Make channel listen for signals from OS
gracefulStop := make(chan os.Signal, 1)
signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT)
<-gracefulStop
logrus.Info("Gracefully shutting down, cleaning up.")
cleanup()
logrus.Info("Clean up success. Good Bye")
}