diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index fdafa1bf..1800082a 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -48,11 +48,11 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Error("invalid format of websocket render image message", err) return } - //颜色/模板标签/logo变更 - ifCancelOldCtx := false - /*if renderImageData.RenderData.TemplateTag != w.extendRenderProperty.templateTag { + //颜色/模板标签/logo变更(后面再开启) + /*ifCancelOldCtx := false + if renderImageData.RenderData.TemplateTag != w.extendRenderProperty.templateTag { ifCancelOldCtx = true - }*/ + } if renderImageData.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex { ifCancelOldCtx = true } @@ -68,7 +68,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { w.extendRenderProperty.renderCtxCancelFunc() //重新赋值 w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx) - } + }*/ select { case <-w.closeChan: //已经关闭 return @@ -95,20 +95,6 @@ func (w *wsConnectItem) consumeRenderImageData() { case <-w.closeChan: //已关闭 return case data := <-w.extendRenderProperty.renderChan: //消费数据 - //标签不一样 - /*if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag { - //logx.Info("标签不一致,丢弃消息") - continue - }*/ - //颜色不一致 - if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex { - //logx.Info("颜色不一致,丢弃消息") - continue - } - //logo不一样 - if data.RenderData.Logo != w.extendRenderProperty.Logo { - continue - } limitChan <- struct{}{} go func(d websocket_data.RenderImageReqMsg) { defer func() { @@ -122,19 +108,22 @@ func (w *wsConnectItem) consumeRenderImageData() { defer func() { <-limitChan }() - go func() { - defer func() { - if err := recover(); err != nil { - logx.Error("func renderImage panic:", err) + //如果不是无视上下文切换取消的(后面再开启) + /*if !d.IgnoreContextCancel { + go func() { + defer func() { + if err := recover(); err != nil { + logx.Error("func renderImage panic:", err) + } + }() + select { + case <-w.extendRenderProperty.renderCtx.Done(): + panic("检测到模板标签/颜色/logo变化,渲染取消旧的任务") + case <-tmpChan: + return } }() - select { - case <-w.extendRenderProperty.renderCtx.Done(): - panic("检测到模板标签/颜色/logo变化,渲染取消旧的任务") - case <-tmpChan: - return - } - }() + }*/ w.renderImage(d) }(data) } diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index c8b857af..508640e2 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -2,8 +2,9 @@ package websocket_data // websocket接受要云渲染处理的数据 type RenderImageReqMsg struct { - RequestId string `json:"request_id"` - RenderData RenderData `json:"render_data"` //渲染主要参数 + RequestId string `json:"request_id"` + IgnoreContextCancel bool `json:"ignore_context_cancel"` //是否无视切换上下文取消正在执行的渲染任务 + RenderData RenderData `json:"render_data"` //渲染主要参数 } type RenderData struct { TemplateTag string `json:"template_tag"` //模板标签(必须)