Compare commits

..

No commits in common. "master" and "feature/rzy/report_combine" have entirely different histories.

2 changed files with 2 additions and 13 deletions

View File

@ -115,7 +115,6 @@ func (s *SendCardClient) NewCard(ctx context.Context, cardSend *CardSend) error
s.processContentChannel(ctx, cardSend, cardInstanceId.String(), client) s.processContentChannel(ctx, cardSend, cardInstanceId.String(), client)
}() }()
wg.Wait() wg.Wait()
log.Info("处理通道结束")
} }
return nil return nil
@ -164,7 +163,7 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
var ( var (
contentBuilder strings.Builder contentBuilder strings.Builder
lastUpdate = time.Now() lastUpdate time.Time
) )
for { for {
@ -174,7 +173,6 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
// 通道关闭,发送最终内容 // 通道关闭,发送最终内容
if contentBuilder.Len() > 0 { if contentBuilder.Len() > 0 {
if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil { if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil {
log.Info("contentBuilder.Len()修改失败1")
s.logger.Errorf("更新卡片失败1:%s", err.Error()) s.logger.Errorf("更新卡片失败1:%s", err.Error())
} }
} }
@ -183,7 +181,6 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
contentBuilder.WriteString(content) contentBuilder.WriteString(content)
if contentBuilder.Len() > 0 { if contentBuilder.Len() > 0 {
if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil { if err := s.updateCardContent(ctx, cardSend, cardInstanceId, contentBuilder.String(), client); err != nil {
log.Info("contentBuilder.Len()修改失败2")
s.logger.Errorf("更新卡片失败2%s", err.Error()) s.logger.Errorf("更新卡片失败2%s", err.Error())
} }
} }
@ -191,12 +188,10 @@ func (s *SendCardClient) processContentChannel(ctx context.Context, cardSend *Ca
case <-heartbeatTicker.C: case <-heartbeatTicker.C:
if time.Now().Unix()-lastUpdate.Unix() >= HeardBeatX { if time.Now().Unix()-lastUpdate.Unix() >= HeardBeatX {
log.Infof("心跳超时,当前时间:%d,最后时间:%d", time.Now().Unix(), lastUpdate.Unix())
return return
} }
case <-ctx.Done(): case <-ctx.Done():
log.Info("send_card上下文失效")
s.logger.Info("context canceled, stop channel processing") s.logger.Info("context canceled, stop channel processing")
return return
} }

View File

@ -64,15 +64,9 @@ func (d *DingBotService) runBackgroundTasks(ctx context.Context, data *chatbot.B
g.Go(func() error { g.Go(func() error {
defer func() { defer func() {
// 确保通道最终关闭 // 确保通道最终关闭
log.Println("流式处理协程关闭")
close(resChan) close(resChan)
}() }()
err := d.dingTalkBotBiz.HandleStreamRes(ctx, data, resChan) return d.dingTalkBotBiz.HandleStreamRes(ctx, data, resChan)
if err != nil {
log.Println("流式回复产生错误,错误:", err.Error())
}
return err
}) })
// 2. 业务处理协程负责关闭requireData.Ch // 2. 业务处理协程负责关闭requireData.Ch