This commit is contained in:
laodaming 2023-07-26 12:27:34 +08:00
parent b9afdf1dda
commit 16feddfe3e
2 changed files with 39 additions and 22 deletions

View File

@ -241,37 +241,30 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
key := w.getRenderImageMapKey(v.ProductId, v.SizeId, v.TemplateId)
w.renderImage[key] = struct{}{}
}
//TODO 发送数据到云渲染服务器
default:
}
}
// 把渲染好的数据放入outchan
func (w *wsConnectItem) setOutRenderImage(req *types.RenderNotifyReq) {
w.mutex.Lock()
defer w.mutex.Unlock()
for _, notifyItem := range req.NotifyList {
renderKey := w.getRenderImageMapKey(notifyItem.ProductId, notifyItem.SizeId, notifyItem.TemplateId)
//查询
_, ok := w.renderImage[renderKey]
if !ok {
continue
}
responseData := types.RenderImageRspMsg{
ProductId: notifyItem.ProductId,
SizeId: notifyItem.SizeId,
TemplateId: notifyItem.TemplateId,
Source: "我是渲染资源",
}
b, _ := json.Marshal(responseData)
// 把要传递给客户端的数据放入outchan
func (w *wsConnectItem) sendToOutChan(data [][]byte) {
for _, v := range data {
select {
case <-w.closeChan:
return
case w.outChan <- b:
case w.outChan <- v:
logx.Info("notify send render result to out chan")
}
//删掉已经处理的渲染任务
delete(w.renderImage, renderKey)
}
}
// 删除对应需要渲染的map值
func (w *wsConnectItem) deleteRenderMapVal(keys []string) {
w.mutex.Lock()
defer w.mutex.Unlock()
for _, v := range keys {
delete(w.renderImage, v)
}
}

View File

@ -58,11 +58,35 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
}
//遍历websocket链接把数据传进去
mapConnPool.Range(func(key, value any) bool {
//断言连接
ws, ok := value.(wsConnectItem)
if !ok {
return false
}
ws.setOutRenderImage(req)
dataList := make([][]byte, 0, len(req.NotifyList))
deleteRenderKey := make([]string, 0, len(req.NotifyList))
//遍历数据
for _, notifyItem := range req.NotifyList {
renderKey := ws.getRenderImageMapKey(notifyItem.ProductId, notifyItem.SizeId, notifyItem.TemplateId)
//查询
_, ok = ws.renderImage[renderKey]
if !ok {
continue
}
responseData := types.RenderImageRspMsg{
ProductId: notifyItem.ProductId,
SizeId: notifyItem.SizeId,
TemplateId: notifyItem.TemplateId,
Source: "我是渲染资源",
}
b, _ := json.Marshal(responseData)
dataList = append(dataList, b)
deleteRenderKey = append(deleteRenderKey, renderKey)
}
//删除对应的需要渲染的图片map
ws.deleteRenderMapVal(deleteRenderKey)
//发送数据
ws.sendToOutChan(dataList)
return true
})
return resp.SetStatus(basic.CodeOK)