-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
64 lines (48 loc) · 1.45 KB
/
server.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
package main
import (
"context"
"log"
"net/http"
"os"
ossignal "os/signal"
"syscall"
"github.com/gin-gonic/gin"
"github.com/roychowdhuryrohit-dev/BackgroundJobManager/config"
"github.com/roychowdhuryrohit-dev/BackgroundJobManager/routes"
"github.com/roychowdhuryrohit-dev/BackgroundJobManager/signals"
)
func main() {
router := gin.Default()
// Set a lower memory limit for multipart forms (default is 32 MiB)
router.MaxMultipartMemory = 8 << 20
signals.Init()
config.Config()
router.POST("/uploadCSV", routes.CreateUpload)
router.POST("/exportData", routes.CreateExport)
router.POST("/createBulkTeam", routes.CreateBulkTeam)
router.GET("/updateTask", routes.UpdateTask)
host, _ := config.ConfigMap.Load(config.HostAddr)
server := &http.Server{
Addr: host.(string),
Handler: router,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf(err.Error())
}
}()
//Gracefully shut down server on OS interrupt.
quit := make(chan os.Signal, 1)
ossignal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down server.")
if err := server.Shutdown(context.Background()); err != nil {
log.Println("Server shutdown error - " + err.Error())
}
//Signal all workers to terminate
signals.CloseAll()
//Wait for remaining workers to terminate.
signals.WorkersGroup.Wait()
log.Println("All workers terminated.")
log.Println("---Server exited gracefully---")
}