diff --git a/server/websocket/internal/handler/datatransferhandler.go b/server/websocket/internal/handler/datatransferhandler.go index d981d377..04f0a7ae 100644 --- a/server/websocket/internal/handler/datatransferhandler.go +++ b/server/websocket/internal/handler/datatransferhandler.go @@ -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) diff --git a/server/websocket/internal/handler/rendernotifyhandler.go b/server/websocket/internal/handler/rendernotifyhandler.go index 3767bd9c..b51fee32 100644 --- a/server/websocket/internal/handler/rendernotifyhandler.go +++ b/server/websocket/internal/handler/rendernotifyhandler.go @@ -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) - } -}