main.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/job/main/passport-game-data/conf"
  10. "go-common/app/job/main/passport-game-data/http"
  11. "go-common/app/job/main/passport-game-data/service"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  14. )
  15. var (
  16. mode int
  17. compareMidListFile string
  18. diffLogFile string
  19. diffParseResFile string
  20. )
  21. const (
  22. _modeNormal = 0
  23. _modeCompareOnly = 1
  24. _modeParseDiffLog = 2
  25. _modeInitCloud = 3
  26. )
  27. func init() {
  28. flag.IntVar(&mode, "mode", _modeNormal, "mode for starting this job, 0 for normal, 1 for compare only, 2 for parse diff log")
  29. flag.StringVar(&compareMidListFile, "compare_mid_list_file", "/tmp/mids.txt", "compare mid list file path")
  30. flag.StringVar(&diffLogFile, "diff_log_file", "/tmp/diff.txt", "diff log file path")
  31. flag.StringVar(&diffParseResFile, "diff_parse_res_file", "/tmp/diff_parse_res.txt", "diff parse result file path")
  32. }
  33. func main() {
  34. flag.Parse()
  35. if err := conf.Init(); err != nil {
  36. panic(err)
  37. }
  38. log.Init(conf.Conf.Xlog)
  39. defer log.Close()
  40. trace.Init(conf.Conf.Tracer)
  41. defer trace.Close()
  42. var srv *service.Service
  43. switch mode {
  44. case _modeCompareOnly:
  45. s := service.NewCompareOnly(conf.Conf)
  46. if err := s.CompareFromMidListFile(context.TODO(), compareMidListFile); err != nil {
  47. log.Error("service.CompareFromMidListFile(%s) error(%v)", compareMidListFile, err)
  48. }
  49. case _modeParseDiffLog:
  50. log.Info("parse diff log from %s", diffLogFile)
  51. if err := service.ParseDiffLog(diffLogFile, diffParseResFile); err != nil {
  52. log.Error("service.ParseDiffLog(%s) error(%v)", diffLogFile, err)
  53. }
  54. time.Sleep(time.Second * 2)
  55. return
  56. case _modeInitCloud:
  57. s := service.NewInitCloud(conf.Conf)
  58. s.InitCloud(context.TODO())
  59. time.Sleep(time.Second * 2)
  60. case _modeNormal:
  61. // service init
  62. srv = service.New(conf.Conf)
  63. http.Init(conf.Conf, srv)
  64. // signal handler
  65. log.Info("passport-game-data-job start")
  66. }
  67. c := make(chan os.Signal, 1)
  68. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  69. for {
  70. s := <-c
  71. log.Info("passport-game-data-job get a signal %s", s.String())
  72. switch s {
  73. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  74. if srv != nil {
  75. srv.Close()
  76. }
  77. log.Info("passport-game-data-job exit")
  78. return
  79. case syscall.SIGHUP:
  80. // TODO reload
  81. default:
  82. return
  83. }
  84. }
  85. }