fix
This commit is contained in:
parent
624b90260f
commit
a106082364
|
@ -3,7 +3,6 @@ package logic
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
|
@ -108,7 +107,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||
inChan: make(chan []byte, 1000),
|
||||
outChan: make(chan []byte, 1000),
|
||||
renderProperty: renderProperty{
|
||||
renderImageTask: make(map[string]struct{}),
|
||||
renderImageTask: make(map[string]string),
|
||||
renderImageTaskCtlChan: make(chan renderImageControlChanItem, 100),
|
||||
},
|
||||
}
|
||||
|
@ -250,11 +249,6 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
// 获取需要渲染图片的map key
|
||||
func (w *wsConnectItem) getRenderImageMapKey(productId, templateTagId, logoId int64, algorithmVersion string) string {
|
||||
return fmt.Sprintf("%d-%d-%d-%s", productId, templateTagId, logoId, algorithmVersion)
|
||||
}
|
||||
|
||||
// 格式化返回数据
|
||||
func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte {
|
||||
d := types.DataTransferData{
|
||||
|
|
|
@ -61,21 +61,20 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq) (resp *basi
|
|||
if ws.isClose {
|
||||
return true
|
||||
}
|
||||
renderKey := ws.getRenderImageMapKey(req.Info.ProductId, req.Info.TemplateTagId, req.Info.LogoId, req.Info.AlgorithmVersion)
|
||||
//查询有无该渲染任务
|
||||
_, ok = ws.renderProperty.renderImageTask[renderKey]
|
||||
renderId, ok := ws.renderProperty.renderImageTask[req.Info.TaskId]
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
b := ws.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, types.RenderImageRspMsg{
|
||||
ProductId: req.Info.ProductId,
|
||||
TemplateTagId: req.Info.TemplateTagId,
|
||||
Image: req.Info.Image,
|
||||
RenderId: renderId,
|
||||
Image: req.Info.Image,
|
||||
})
|
||||
//删除对应的需要渲染的图片map
|
||||
ws.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 0, //0删除 1添加
|
||||
Key: renderKey,
|
||||
Option: 0, //0删除 1添加
|
||||
TaskId: req.Info.TaskId,
|
||||
RenderId: renderId,
|
||||
}
|
||||
//发送数据到out chan
|
||||
ws.sendToOutChan(b)
|
||||
|
|
|
@ -4,38 +4,21 @@ import (
|
|||
"encoding/json"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
"fusenapi/utils/hash"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// 云渲染属性
|
||||
type renderProperty struct {
|
||||
renderImageTask map[string]struct{} //需要渲染的图片任务
|
||||
renderImageTask map[string]string //需要渲染的图片任务 key是taskId val 是renderId
|
||||
renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增移除的控制通道
|
||||
}
|
||||
|
||||
// 渲染任务新增移除的控制通道的数据
|
||||
type renderImageControlChanItem struct {
|
||||
Option int // 0删除 1添加
|
||||
Key string //map的key
|
||||
}
|
||||
|
||||
// 操作连接中渲染任务的增加/删除
|
||||
func (w *wsConnectItem) operationRenderTask() {
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan:
|
||||
return
|
||||
case data := <-w.renderProperty.renderImageTaskCtlChan:
|
||||
switch data.Option {
|
||||
case 0: //删除任务
|
||||
delete(w.renderProperty.renderImageTask, data.Key)
|
||||
case 1: //新增任务
|
||||
w.renderProperty.renderImageTask[data.Key] = struct{}{}
|
||||
default:
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Option int // 0删除 1添加
|
||||
TaskId string //map的key
|
||||
RenderId string // map的val
|
||||
}
|
||||
|
||||
// 渲染请求数据处理发送云渲染服务处理
|
||||
|
@ -48,23 +31,39 @@ func (w *wsConnectItem) SendToCloudRender(data []byte) {
|
|||
}
|
||||
logx.Info("收到请求云渲染图片数据:", renderImageData)
|
||||
//把需要渲染的图片任务加进去
|
||||
for _, productId := range renderImageData.ProductIds {
|
||||
select {
|
||||
case <-w.closeChan: //连接关闭了
|
||||
select {
|
||||
case <-w.closeChan: //连接关闭了
|
||||
return
|
||||
default:
|
||||
//加入渲染任务
|
||||
taskId := hash.JsonHashKey(renderImageData.RenderData)
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
TaskId: taskId,
|
||||
RenderId: renderImageData.RenderId,
|
||||
}
|
||||
//发送给对应的流水线组装数据
|
||||
if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, data); err != nil {
|
||||
logx.Error("发送渲染任务数据到MQ失败:", string(data), "err:", err)
|
||||
return
|
||||
default:
|
||||
//加入渲染任务
|
||||
key := w.getRenderImageMapKey(productId, renderImageData.TemplateTagId, renderImageData.LogoId, renderImageData.AlgorithmVersion)
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
Key: key,
|
||||
}
|
||||
logx.Info("发送渲染数据到rabbitmq成功:", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
// 操作连接中渲染任务的增加/删除
|
||||
func (w *wsConnectItem) operationRenderTask() {
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan:
|
||||
return
|
||||
case data := <-w.renderProperty.renderImageTaskCtlChan:
|
||||
switch data.Option {
|
||||
case 0: //删除任务
|
||||
delete(w.renderProperty.renderImageTask, data.TaskId)
|
||||
case 1: //新增任务
|
||||
w.renderProperty.renderImageTask[data.TaskId] = data.RenderId
|
||||
}
|
||||
//发送给对应的流水线组装数据
|
||||
if err := w.rabbitMq.SendMsg(constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, data); err != nil {
|
||||
logx.Error("发送渲染任务数据到MQ失败:", string(data), "err:", err)
|
||||
continue
|
||||
}
|
||||
logx.Info("发送渲染数据到rabbitmq成功:", string(data))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,18 +11,13 @@ type DataTransferData struct {
|
|||
}
|
||||
|
||||
type RenderImageReqMsg struct {
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
RenderData interface{} `json:"render_data"` //参数数据
|
||||
}
|
||||
|
||||
type RenderImageRspMsg struct {
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
Image string `json:"image"` //渲染后的图片
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
Image string `json:"image"` //渲染结果图片
|
||||
}
|
||||
|
||||
type ThirdPartyLoginRspMsg struct {
|
||||
|
@ -36,11 +31,8 @@ type RenderNotifyReq struct {
|
|||
}
|
||||
|
||||
type NotifyInfo struct {
|
||||
ProductId int64 `json:"product_id"` //产品id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
Image string `json:"image"`
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
Image string `json:"image"`
|
||||
}
|
||||
|
||||
type ThirdPartyLoginNotifyReq struct {
|
||||
|
|
|
@ -26,17 +26,12 @@ type DataTransferData {
|
|||
D interface{} `json:"d"` //传递的消息
|
||||
}
|
||||
type RenderImageReqMsg { //websocket接受要云渲染处理的数据
|
||||
ProductIds []int64 `json:"product_ids"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
RenderData interface{} `json:"render_data"` //参数数据
|
||||
}
|
||||
type RenderImageRspMsg { //websocket发送渲染完的数据
|
||||
ProductId int64 `json:"product_id"` //产品 id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
Image string `json:"image"` //渲染后的图片
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
Image string `json:"image"` //渲染结果图片
|
||||
}
|
||||
type ThirdPartyLoginRspMsg { //websocket三方登录的通知数据
|
||||
Token string `json:"token"`
|
||||
|
@ -48,11 +43,8 @@ type RenderNotifyReq {
|
|||
Info NotifyInfo `json:"info"`
|
||||
}
|
||||
type NotifyInfo {
|
||||
ProductId int64 `json:"product_id"` //产品id
|
||||
TemplateTagId int64 `json:"template_tag_id"` //模板标签id
|
||||
AlgorithmVersion string `json:"algorithm_version,optional"` //算法版本
|
||||
LogoId int64 `json:"logo_id"` //logoid
|
||||
Image string `json:"image"`
|
||||
TaskId string `json:"task_id"` //任务id
|
||||
Image string `json:"image"`
|
||||
}
|
||||
//第三方登录通知接口
|
||||
type ThirdPartyLoginNotifyReq {
|
||||
|
|
Loading…
Reference in New Issue
Block a user