main.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/live/recommend-job/internal/conf"
  9. "go-common/app/job/live/recommend-job/internal/server/http"
  10. "go-common/app/job/live/recommend-job/internal/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  14. )
  15. var itemCFRun = false
  16. var itemCFInputPath = ""
  17. var itemCFWorkerNum = 1000
  18. var userAreaRun = false
  19. var uerAreaInputPath = ""
  20. func main() {
  21. flag.BoolVar(&userAreaRun, "userarea.run", false, "用户分区缓存:是否手动跑")
  22. flag.StringVar(&uerAreaInputPath, "userarea.input", "", "用户分区缓存:输入文件地址")
  23. flag.BoolVar(&itemCFRun, "itemcf.run", false, "协同过滤推荐缓存到redis:是否手动跑")
  24. flag.StringVar(&itemCFInputPath, "itemcf.input", "", "协同过滤结果文件地址")
  25. flag.IntVar(&itemCFWorkerNum, "itemcf.workerNum", 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-job start")
  33. trace.Init(conf.Conf.Tracer)
  34. defer trace.Close()
  35. ecode.Init(conf.Conf.Ecode)
  36. if itemCFRun {
  37. c := conf.Conf.ItemCFJob
  38. c.InputFile = itemCFInputPath
  39. c.WorkerNum = itemCFWorkerNum
  40. var job = service.ItemCFJob{
  41. Conf: c,
  42. RedisConf: conf.Conf.Redis,
  43. HadoopConf: conf.Conf.Hadoop,
  44. }
  45. job.Run()
  46. os.Exit(0)
  47. }
  48. if userAreaRun {
  49. c := conf.Conf.UserAreaJob
  50. c.InputFile = uerAreaInputPath
  51. c.WorkerNum = 1000
  52. var job = service.UserAreaJob{
  53. JobConf: c,
  54. RedisConf: conf.Conf.Redis,
  55. HadoopConf: conf.Conf.Hadoop,
  56. }
  57. job.Run()
  58. os.Exit(0)
  59. }
  60. svc := service.New(conf.Conf)
  61. http.Init(conf.Conf, svc)
  62. svc.RunCrontab()
  63. c := make(chan os.Signal, 1)
  64. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  65. for {
  66. s := <-c
  67. log.Info("get a signal %s", s.String())
  68. switch s {
  69. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  70. svc.Close()
  71. log.Info("recommend-job exit")
  72. time.Sleep(time.Second)
  73. return
  74. case syscall.SIGHUP:
  75. default:
  76. return
  77. }
  78. }
  79. }