by Robin at 20240530

This commit is contained in:
Leufolium 2024-05-30 15:37:56 +08:00
parent a6e3a3ee12
commit ba5cd815ad
1 changed files with 19 additions and 7 deletions

View File

@ -47,16 +47,12 @@ func (s *StreamerRecommService) SetOut(out func([]int64) error) {
func (s *StreamerRecommService) RunBatch(nt int64) error {
ctx := &gin.Context{}
// 获取计算公式
s.formula = &apollostruct.StreamerScoreFormulaCfg{}
err := apollo.GetJson(consts.StreamerScoreFormulaKey, s.formula, apollo.ApolloOpts().SetNamespace("application"))
err := s.init()
if err != nil {
logger.Error("Apollo read failed : %v", err)
logger.Error("init fail, err: %v", err)
s.clear()
return fmt.Errorf("apollo read failed : %v", err)
return err
}
// 获取优先级
s.formula.CalPriority()
// 取数
err = s.recvMsg(ctx, nt)
@ -92,6 +88,22 @@ func (s *StreamerRecommService) RunBatch(nt int64) error {
}
func (s *StreamerRecommService) init() error {
s.clear()
// 获取计算公式
s.formula = &apollostruct.StreamerScoreFormulaCfg{}
err := apollo.GetJson(consts.StreamerScoreFormulaKey, s.formula, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
s.clear()
return fmt.Errorf("apollo read failed : %v", err)
}
// 获取优先级
s.formula.CalPriority()
return nil
}
func (s *StreamerRecommService) clear() {
s.scorelist = make([]*StreamerScore, 0)
s.scores = make(map[int64]*StreamerScore)