This commit is contained in:
laodaming 2023-09-22 15:12:44 +08:00
parent c8a52321a5
commit bfea40c643
2 changed files with 6 additions and 36 deletions

View File

@ -3,7 +3,6 @@ package logic
//处理websocket云渲染任务数据
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -24,7 +23,7 @@ var (
//每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500
//每个websocket渲染并发数
renderChanConcurrency = 3
renderChanConcurrency = 1
)
// 渲染处理器
@ -34,8 +33,6 @@ type renderProcessor struct {
// 云渲染属性
type extendRenderProperty struct {
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
selectColorIndex int //颜色选中索引
templateTag string //模板标签
}
// 处理分发到这里的数据
@ -47,8 +44,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
logx.Error("invalid format of websocket render image message", err)
return
}
w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag
w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
select {
case <-w.closeChan: //已经关闭
return
@ -61,54 +56,29 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
func (w *wsConnectItem) consumeRenderImageData() {
defer func() {
if err := recover(); err != nil {
logx.Error("func consumeRenderImageData err:", err)
logx.Error("func consumeRenderImageData panic:", err)
}
}()
//限制并发
limitChan := make(chan struct{}, renderChanConcurrency)
defer close(limitChan)
ctlCtx ,cancel:= context.WithCancel(w.logic.ctx)
for {
select {
case <-w.closeChan: //已关闭
return
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)
limitChan <- struct{}{}
go func(ctx context.Context,d websocket_data.RenderImageReqMsg) {
go func(d websocket_data.RenderImageReqMsg) {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage err:", err)
logx.Error("func renderImage panic:", err)
}
}()
defer func() {
<-limitChan
}()
go func() {
defer func() {
if err := recover(); err != nil {
logx.Error( err)
}
}()
select {
case <-ctx.Done() :
panic("渲染截止")
}
}()
w.renderImage(d)
}(ctlCtx,data)
}(data)
}
}
}

View File

@ -318,7 +318,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
err = curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl,
Url: constants.BLMServiceUrlLogoCombine,
RequireTimeout: time.Second * 30,
RequireTimeout: time.Second * 15,
}).PostJson(postMap, &resultBLM)
logc.Infof(ctx, "合图--算法请求--合图--结束时间:%v", time.Now().UTC())