This commit is contained in:
laodaming 2023-09-22 14:57:56 +08:00
parent c2bb174574
commit 129583d19a

View File

@ -3,6 +3,7 @@ package logic
//处理websocket云渲染任务数据
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -66,6 +67,7 @@ func (w *wsConnectItem) consumeRenderImageData() {
//限制并发
limitChan := make(chan struct{}, renderChanConcurrency)
defer close(limitChan)
ctlCtx ,cancel:= context.WithCancel(w.logic.ctx)
for {
select {
case <-w.closeChan: //已关闭
@ -73,15 +75,19 @@ func (w *wsConnectItem) consumeRenderImageData() {
case data := <-w.extendRenderProperty.renderChan: //消费数据
if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag{
logx.Info("由于模板切换了,丢弃该渲染消息")
cancel()
ctlCtx ,cancel= context.WithCancel(w.logic.ctx)
continue
}
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex{
logx.Info("由于模板切换了颜色,丢弃该渲染消息")
cancel()
ctlCtx ,cancel= context.WithCancel(w.logic.ctx)
continue
}
logx.Info("***************用户id:",w.userId," 游客id:",w.guestId," 当前模板标签:",w.extendRenderProperty.templateTag, " 消息模板标签:",data.RenderData.TemplateTag ," 当前颜色索引:",w.extendRenderProperty.selectColorIndex," 消息颜色索引:",data.RenderData.TemplateTagColor.SelectedColorIndex)
logx.Info("用户id:",w.userId," 游客id:",w.guestId," 当前模板标签:",w.extendRenderProperty.templateTag, " 消息模板标签:",data.RenderData.TemplateTag ," 当前颜色索引:",w.extendRenderProperty.selectColorIndex," 消息颜色索引:",data.RenderData.TemplateTagColor.SelectedColorIndex)
limitChan <- struct{}{}
go func(d websocket_data.RenderImageReqMsg) {
go func(ctx context.Context,d websocket_data.RenderImageReqMsg) {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage err:", err)
@ -90,8 +96,14 @@ func (w *wsConnectItem) consumeRenderImageData() {
defer func() {
<-limitChan
}()
go func() {
select {
case <-ctx.Done() :
panic("渲染截止")
}
}()
w.renderImage(d)
}(data)
}(ctlCtx,data)
}
}
}