main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/live/recommend/internal/conf"
  9. "go-common/app/service/live/recommend/internal/dao"
  10. "go-common/app/service/live/recommend/internal/server/grpc"
  11. "go-common/app/service/live/recommend/internal/server/http"
  12. "go-common/app/service/live/recommend/internal/service"
  13. ecode "go-common/library/ecode/tip"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. )
  17. var runJob = false
  18. var jobFilePath = ""
  19. var jobWorkerNum = 1000
  20. var jobOffset = -1
  21. func main() {
  22. flag.BoolVar(&runJob, "runJob", false, "跑redis脚本")
  23. flag.StringVar(&jobFilePath, "jobFile", "", "推荐文件地址")
  24. flag.IntVar(&jobOffset, "jobOffset", -1, "操作偏移,即从n行开始跑, 默认会从上一次中断的地方开始")
  25. flag.IntVar(&jobWorkerNum, "jobWorkerNum", 1000, "worker数量")
  26. flag.Parse()
  27. if err := conf.Init(); err != nil {
  28. panic(err)
  29. }
  30. log.Init(conf.Conf.Log)
  31. defer log.Close()
  32. log.Info("recommend-service start")
  33. trace.Init(conf.Conf.Tracer)
  34. defer trace.Close()
  35. ecode.Init(conf.Conf.Ecode)
  36. svc := service.New(conf.Conf)
  37. http.Init(conf.Conf, svc)
  38. grpc.Init(conf.Conf)
  39. go dao.StartRefreshJob()
  40. go dao.StartRoomFeatureJob(conf.Conf)
  41. c := make(chan os.Signal, 1)
  42. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  43. for {
  44. s := <-c
  45. log.Info("get a signal %s", s.String())
  46. switch s {
  47. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  48. svc.Close()
  49. log.Info("recommend-service exit")
  50. time.Sleep(time.Second)
  51. return
  52. case syscall.SIGHUP:
  53. default:
  54. return
  55. }
  56. }
  57. }