fix
This commit is contained in:
parent
222b9ec155
commit
743ea96157
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user