This commit is contained in:
laodaming 2023-07-25 19:33:59 +08:00
parent 222b9ec155
commit 743ea96157
2 changed files with 30 additions and 31 deletions

View File

@ -225,6 +225,35 @@ func (w *wsConnectItem) dealwithReciveData(data []byte) {
}
}
// 把渲染好的数据放入outchan
func (w *wsConnectItem) setOutRenderImage(req types.RenderNotifyReq, ws wsConnectItem) {
ws.mutex.Lock()
defer ws.mutex.Unlock()
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)
select {
case <-ws.closeChan:
return
case ws.outChan <- b:
logx.Info("notify send render result to out chan")
}
//删掉已经处理的渲染任务
delete(ws.renderImage, renderKey)
}
}
// 获取需要渲染图片的map key
func (w *wsConnectItem) getRenderImageMapKey(productId, sizeId, templateId int64) string {
return fmt.Sprintf("%d-%d-%d", productId, sizeId, templateId)

View File

@ -7,7 +7,6 @@ import (
"fmt"
"fusenapi/constants"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"net/http"
"time"
@ -64,7 +63,7 @@ func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
if !ok {
return false
}
setOutRenderImage(req, ws)
ws.setOutRenderImage(req, ws)
return true
})
httpx.OkJsonCtx(r.Context(), w, basic.Response{
@ -74,32 +73,3 @@ func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
})
}
}
// 把渲染好的数据放入outchan
func setOutRenderImage(req types.RenderNotifyReq, ws wsConnectItem) {
ws.mutex.Lock()
defer ws.mutex.Unlock()
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)
select {
case <-ws.closeChan:
return
case ws.outChan <- b:
logx.Info("notify send render result to out chan")
}
//删掉已经处理的渲染任务
delete(ws.renderImage, renderKey)
}
}