main.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/main/playlist/conf"
  9. "go-common/app/job/main/playlist/http"
  10. "go-common/app/job/main/playlist/service"
  11. "go-common/library/log"
  12. "go-common/library/net/trace"
  13. )
  14. func main() {
  15. flag.Parse()
  16. initConf()
  17. initLog()
  18. defer log.Close()
  19. log.Info("playlist-job start")
  20. srv := service.New(conf.Conf)
  21. http.Init(conf.Conf, srv)
  22. initSignal(srv)
  23. }
  24. func initConf() {
  25. if err := conf.Init(); err != nil {
  26. panic(err)
  27. }
  28. }
  29. func initLog() {
  30. log.Init(conf.Conf.Log)
  31. trace.Init(conf.Conf.Tracer)
  32. defer trace.Close()
  33. }
  34. func initSignal(srv *service.Service) {
  35. c := make(chan os.Signal, 1)
  36. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. s := <-c
  39. log.Info("playlist-job get a signal: %s", s.String())
  40. switch s {
  41. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  42. if err := srv.Close(); err != nil {
  43. log.Error("srv close consumer error(%v)", err)
  44. }
  45. time.Sleep(time.Second)
  46. return
  47. case syscall.SIGHUP:
  48. // TODO: reload
  49. default:
  50. return
  51. }
  52. }
  53. }