main.go 777 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/up-rating/conf"
  8. "go-common/app/job/main/up-rating/http"
  9. "go-common/library/log"
  10. )
  11. func main() {
  12. flag.Parse()
  13. if err := conf.Init(); err != nil {
  14. panic(err)
  15. }
  16. log.Init(conf.Conf.Log)
  17. http.Init(conf.Conf)
  18. signalHandler()
  19. }
  20. func signalHandler() {
  21. var ch = make(chan os.Signal, 1)
  22. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  23. for {
  24. si := <-ch
  25. log.Info("up-rating-job get a signal %s", si.String())
  26. switch si {
  27. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  28. log.Info("get a signal %s, stop the consume process", si.String())
  29. http.Close()
  30. return
  31. case syscall.SIGHUP:
  32. default:
  33. return
  34. }
  35. }
  36. }