From ba5cd815ade6d6f37226b0b93c12d65ccf9b5af1 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 30 May 2024 15:37:56 +0800 Subject: [PATCH] by Robin at 20240530 --- app/mix/service/streamer_recomm_service.go | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/mix/service/streamer_recomm_service.go b/app/mix/service/streamer_recomm_service.go index 042758f9..8587e7ff 100644 --- a/app/mix/service/streamer_recomm_service.go +++ b/app/mix/service/streamer_recomm_service.go @@ -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)