This commit is contained in:
laodaming 2023-11-10 10:23:26 +08:00
parent 5c1f33a8a8
commit 360c19a8f5
6 changed files with 38 additions and 12 deletions

View File

@ -21,11 +21,12 @@ const (
// websocket消息类型(云渲染类别)
const (
WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息(1级消息双向通信)
WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息1级消息单向通信
WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_ASSEMBLE_RENDER_DATA Websocket = "WEBSOCKET_ASSEMBLE_RENDER_DATA" //组装unity需要的数据 2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_SEND_DATA_TO_UNITY Websocket = "WEBSOCKET_SEND_DATA_TO_UNITY" //发送到unity进行渲染 2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_RENDER_IMAGE Websocket = "WEBSOCKET_RENDER_IMAGE" //图片渲染消息(1级消息双向通信)
WEBSOCKET_RENDER_IMAGE_ERR Websocket = "WEBSOCKET_RENDER_IMAGE_ERR" //图片渲染失败消息1级消息单向通信
WEBSOCKET_COMBINE_IMAGE Websocket = "WEBSOCKET_COMBINE_IMAGE" //反回合成刀版图消息2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_ASSEMBLE_RENDER_DATA Websocket = "WEBSOCKET_ASSEMBLE_RENDER_DATA" //组装unity需要的数据 2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_SEND_DATA_TO_UNITY Websocket = "WEBSOCKET_SEND_DATA_TO_UNITY" //发送到unity进行渲染 2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
WEBSOCKET_REQUIRE_BROWSER_RESEND_RENDER Websocket = "WEBSOCKET_REQUIRE_BROWSER_RESEND_RENDER" //后端请求前端去重发渲染任务事件2级消息单向通信属于 WEBSOCKET_RENDER_IMAGE 消息的子流程)
)
// websocket消息类型系统数据变更通知

View File

@ -114,6 +114,11 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
if ws.conn != nil {
//发送错误信息给前端
ws.renderErrResponse(requestId, info.TemplateTag, info.TaskId, "unity云渲染错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
//发送给前端重发消息
ws.requestResendRenderResponse(websocket_data.RequestBrowserResendRenderEvent{
RequestId: info.RequestId,
Description: "unity require resend",
})
logx.Info("渲染失败且发送了失败信息:", req.Msg)
} else {
logx.Info("渲染失败且找不到ws连接")

View File

@ -81,3 +81,11 @@ func (w *wsConnectItem) renderErrResponse(requestId, templateTag, taskId, descri
}
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, data))
}
// 渲染失败要求重新发起任务
func (w *wsConnectItem) requestResendRenderResponse(data websocket_data.RequestBrowserResendRenderEvent) {
if w.debug == nil {
data.Description = ""
}
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUIRE_BROWSER_RESEND_RENDER, data))
}

View File

@ -32,7 +32,7 @@ func (w *wsConnectItem) sendCombineImageStepResponseMessage(requestId, combineIm
SizeId: sizeId,
ModelId: modelId,
TemplateId: templateId,
CombineProcessTime: websocket_data.CombineProcessTime{
CombineProcessTime: &websocket_data.CombineProcessTime{
CombineTakesTime: combineTakesTime,
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
},

View File

@ -229,7 +229,13 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
}
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
if err != nil {
//发送渲染错误消息
w.renderErrResponse(renderImageData.RequestId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
//发送给前端重发消息
w.requestResendRenderResponse(websocket_data.RequestBrowserResendRenderEvent{
RequestId: renderImageData.RequestId,
Description: "combine require resend",
})
//统计合图失败数
increaseCombineRequestErrorCount(w.userId, w.guestId)
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)

View File

@ -39,12 +39,12 @@ type RenderProcessTime struct {
// 合图返回数据
type CombineImageRspMsg struct {
RequestId string `json:"request_id"`
CombineImage string `json:"combine_image"` //刀版图
SizeId int64 `json:"size_id"` //尺寸id
ModelId int64 `json:"model_id"`
TemplateId int64 `json:"template_id"`
CombineProcessTime CombineProcessTime `json:"combine_process_time"`
RequestId string `json:"request_id"`
CombineImage string `json:"combine_image"` //刀版图
SizeId int64 `json:"size_id"` //尺寸id
ModelId int64 `json:"model_id"`
TemplateId int64 `json:"template_id"`
CombineProcessTime *CombineProcessTime `json:"combine_process_time"`
}
type CombineProcessTime struct {
CombineTakesTime string `json:"combine_takes_time"` //合图时间
@ -71,3 +71,9 @@ type ToUnityIdStruct struct {
UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"`
}
// 要求前端重发渲染消息事件结构
type RequestBrowserResendRenderEvent struct {
RequestId string `json:"request_id"`
Description string `json:"description"`
}