main.go 1012 B

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