fix
This commit is contained in:
parent
84dc60be49
commit
64536beae6
|
@ -49,26 +49,6 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
|||
return errors.New("allmodels is nil!!")
|
||||
}
|
||||
rabbitmq := initalize.RabbitMqHandle{}
|
||||
//查询有没有缓存的资源
|
||||
resource, err := allmodels.FsResource.FindOneById(ctx, parseInfo.TaskId)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("failed to find render resource:", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
//有数据则直接返回
|
||||
cacheData := websocket_data.RenderImageNotify{
|
||||
TaskId: parseInfo.TaskId,
|
||||
Image: *resource.ResourceUrl,
|
||||
}
|
||||
d, _ := json.Marshal(cacheData)
|
||||
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil {
|
||||
logx.Error("failed to send cache render resource to queue:RABBIT_MQ_RENDER_RESULT_DATA")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
timeSearchBegin := time.Now().UnixMilli()
|
||||
//获取模板
|
||||
templateInfo, err := allmodels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId))
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/id_generator"
|
||||
"fusenapi/utils/websocket_data"
|
||||
|
@ -64,7 +65,9 @@ var (
|
|||
// 每个连接的连接基本属性
|
||||
type wsConnectItem struct {
|
||||
conn *websocket.Conn //websocket的连接
|
||||
ctx context.Context
|
||||
rabbitMq *initalize.RabbitMqHandle
|
||||
allModels *gmodel.AllModelsGen
|
||||
closeChan chan struct{} //ws连接关闭chan
|
||||
isClose bool //是否已经关闭
|
||||
uniqueId uint64 //ws连接唯一标识
|
||||
|
@ -110,7 +113,9 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||
uniqueId := websocketIdGenerator.Get()
|
||||
ws := wsConnectItem{
|
||||
conn: conn,
|
||||
ctx: l.ctx,
|
||||
rabbitMq: l.svcCtx.RabbitMq,
|
||||
allModels: l.svcCtx.AllModels,
|
||||
uniqueId: uniqueId,
|
||||
closeChan: make(chan struct{}, 1),
|
||||
inChan: make(chan []byte, 1000),
|
||||
|
|
|
@ -2,10 +2,12 @@ package logic
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/hash"
|
||||
"fusenapi/utils/websocket_data"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 云渲染属性
|
||||
|
@ -33,8 +35,27 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
//用户id赋值
|
||||
renderImageData.RenderData.UserId = w.userId
|
||||
renderImageData.RenderData.GuestId = w.guestId
|
||||
//把需要渲染的图片任务加进去
|
||||
//生成任务id
|
||||
taskId := hash.JsonHashKey(renderImageData.RenderData)
|
||||
//查询有没有缓存的资源,有就返回######################
|
||||
resource, err := w.allModels.FsResource.FindOneById(w.ctx, taskId)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error("failed to find render resource:", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
//返回给客户端
|
||||
b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||
RenderId: renderImageData.RenderId,
|
||||
Image: *resource.ResourceUrl,
|
||||
})
|
||||
//发送数据到out chan
|
||||
w.sendToOutChan(b)
|
||||
return
|
||||
}
|
||||
//###########################################
|
||||
//把需要渲染的图片任务加进去
|
||||
w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{
|
||||
Option: 1, //0删除 1添加
|
||||
TaskId: taskId,
|
||||
|
|
Loading…
Reference in New Issue
Block a user