123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package main
- import (
- "flag"
- "os"
- "os/signal"
- "syscall"
- "time"
- "go-common/app/job/main/activity/conf"
- "go-common/app/job/main/activity/http"
- "go-common/app/job/main/activity/service"
- "go-common/library/log"
- )
- var (
- srv *service.Service
- )
- func main() {
- flag.Parse()
- if err := conf.Init(); err != nil {
- log.Error("conf.Init() error(%v)", err)
- log.Info("conf.Init() error(%v)", err)
- panic(err)
- }
- // init log
- log.Init(conf.Conf.Log)
- defer log.Close()
- log.Info("activity-job start")
- srv = service.New(conf.Conf)
- http.Init(conf.Conf, srv)
- signalHandler()
- }
- func signalHandler() {
- var (
- err error
- ch = make(chan os.Signal, 1)
- )
- signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
- for {
- si := <-ch
- switch si {
- case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
- log.Info("get a signal %s, stop the consume process", si.String())
- if err = srv.Close(); err != nil {
- log.Error("srv close consumer error(%v)", err)
- }
- time.Sleep(5 * time.Second)
- return
- case syscall.SIGHUP:
- default:
- return
- }
- }
- }
|