main.go 898 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/main/credit/conf"
  9. "go-common/app/job/main/credit/http"
  10. "go-common/app/job/main/credit/service"
  11. "go-common/library/log"
  12. )
  13. var (
  14. srv *service.Service
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(); err != nil {
  19. log.Error("conf.Init() error(%v)", err)
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Xlog)
  23. defer log.Close()
  24. log.Info("credit-job start")
  25. http.Init(conf.Conf)
  26. signalHandler()
  27. }
  28. func signalHandler() {
  29. var ch = make(chan os.Signal, 1)
  30. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  31. for {
  32. si := <-ch
  33. switch si {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  35. log.Info("get a signal %s, stop the consume process", si.String())
  36. srv.Close()
  37. time.Sleep(2 * time.Second)
  38. return
  39. case syscall.SIGHUP:
  40. default:
  41. return
  42. }
  43. }
  44. }