fix
This commit is contained in:
parent
ed6326f07d
commit
e3aff09ede
|
@ -45,6 +45,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
||||||
logx.Error("渲染回调参数错误:渲染结果图片数据")
|
logx.Error("渲染回调参数错误:渲染结果图片数据")
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image")
|
||||||
}
|
}
|
||||||
|
unityRenderEndTime := time.Now().UTC().UnixMilli()
|
||||||
//存base64打印测试
|
//存base64打印测试
|
||||||
/* f, _ := os.Create("b.txt")
|
/* f, _ := os.Create("b.txt")
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
@ -70,6 +71,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
||||||
logx.Error("渲染回调上传文件失败:", err)
|
logx.Error("渲染回调上传文件失败:", err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
||||||
}
|
}
|
||||||
|
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
|
||||||
//遍历websocket链接把数据传进去
|
//遍历websocket链接把数据传进去
|
||||||
mapConnPool.Range(func(key, value any) bool {
|
mapConnPool.Range(func(key, value any) bool {
|
||||||
//断言连接
|
//断言连接
|
||||||
|
@ -78,12 +80,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
||||||
logx.Error("渲染回调断言websocket连接失败")
|
logx.Error("渲染回调断言websocket连接失败")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//记录收到unity渲染结果时间
|
//记录收到unity渲染结果时间以及上传渲染图耗时时间
|
||||||
ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
|
ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
|
||||||
Option: 2,
|
Option: 2,
|
||||||
TaskId: req.TaskId,
|
TaskId: req.TaskId,
|
||||||
TaskProperty: renderTask{
|
TaskProperty: renderTask{
|
||||||
UnityRenderEndTime: time.Now().UTC().UnixMilli(),
|
UnityRenderEndTime: unityRenderEndTime,
|
||||||
|
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
//发送处理并删除任务
|
//发送处理并删除任务
|
||||||
|
|
|
@ -36,11 +36,12 @@ type renderImageControlChanItem struct {
|
||||||
|
|
||||||
// 渲染任务属性
|
// 渲染任务属性
|
||||||
type renderTask struct {
|
type renderTask struct {
|
||||||
RenderId string //渲染id(前端传的)
|
RenderId string //渲染id(前端传的)
|
||||||
CombineBeginTime int64 //合图开始时间
|
CombineTakesTime int64 //合刀版图耗时
|
||||||
CombineEndTime int64 //合图结束时间
|
UploadCombineImageTakesTime int64 //上传刀版图耗时
|
||||||
UnityRenderBeginTime int64 //发送给unity时间
|
UnityRenderBeginTime int64 //发送给unity时间
|
||||||
UnityRenderEndTime int64 //unity回调结果时间
|
UnityRenderEndTime int64 //unity回调结果时间
|
||||||
|
UploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送到渲染缓冲池
|
// 发送到渲染缓冲池
|
||||||
|
@ -166,8 +167,8 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
|
||||||
b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||||
RenderId: renderImageData.RenderId,
|
RenderId: renderImageData.RenderId,
|
||||||
Image: *resource.ResourceUrl,
|
Image: *resource.ResourceUrl,
|
||||||
CombineTakesTime: "(缓存)",
|
CombineTakesTime: "cache",
|
||||||
UnityRenderTakesTime: "(缓存)",
|
UnityRenderTakesTime: "cache",
|
||||||
})
|
})
|
||||||
//发送数据到out chan
|
//发送数据到out chan
|
||||||
w.sendToOutChan(b)
|
w.sendToOutChan(b)
|
||||||
|
@ -214,15 +215,6 @@ func (w *wsConnectItem) genRenderTaskId(renderImageData websocket_data.RenderIma
|
||||||
|
|
||||||
// 组装数据发送给unity
|
// 组装数据发送给unity
|
||||||
func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error {
|
func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productFirstSize *gmodel.FsProductSize) error {
|
||||||
|
|
||||||
//记录刀版图合成开始时间
|
|
||||||
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
|
|
||||||
Option: 2,
|
|
||||||
TaskId: taskId,
|
|
||||||
TaskProperty: renderTask{
|
|
||||||
CombineBeginTime: time.Now().UTC().UnixMilli(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
//获取刀版图
|
//获取刀版图
|
||||||
combineReq := repositories.LogoCombineReq{
|
combineReq := repositories.LogoCombineReq{
|
||||||
UserId: info.RenderData.UserId,
|
UserId: info.RenderData.UserId,
|
||||||
|
@ -248,12 +240,13 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
|
logx.Error("合成刀版图失败,合成的刀版图是空指针:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//记录刀版图合成结束时间
|
//记录刀版图合成消耗时间跟上传刀版图时间
|
||||||
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
|
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
|
||||||
Option: 2,
|
Option: 2,
|
||||||
TaskId: taskId,
|
TaskId: taskId,
|
||||||
TaskProperty: renderTask{
|
TaskProperty: renderTask{
|
||||||
CombineEndTime: time.Now().UTC().UnixMilli(),
|
CombineTakesTime: res.DiffTimeLogoCombine,
|
||||||
|
UploadCombineImageTakesTime: res.DiffTimeUploadFile,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
|
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
|
||||||
|
@ -334,15 +327,15 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push"
|
url := w.logic.svcCtx.Config.Unity.Host + "/api/render/queue/push"
|
||||||
header := make(map[string]string)
|
header := make(map[string]string)
|
||||||
header["content-type"] = "application/json"
|
header["content-type"] = "application/json"
|
||||||
t := time.Now().UTC()
|
|
||||||
postData := map[string]interface{}{
|
postData := map[string]interface{}{
|
||||||
"group": "unity3d",
|
"group": "unity3d",
|
||||||
"source": "home page",
|
"source": "home page",
|
||||||
"priority": 1,
|
"priority": 1,
|
||||||
"create_at": t,
|
"create_at": time.Now().UTC(),
|
||||||
"render_data": sendData,
|
"render_data": sendData,
|
||||||
}
|
}
|
||||||
postDataBytes, _ := json.Marshal(postData)
|
postDataBytes, _ := json.Marshal(postData)
|
||||||
|
unityRenderBeginTime := time.Now().UTC().UnixMilli()
|
||||||
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
|
_, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
|
w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id)
|
||||||
|
@ -354,7 +347,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
|
||||||
Option: 2,
|
Option: 2,
|
||||||
TaskId: taskId,
|
TaskId: taskId,
|
||||||
TaskProperty: renderTask{
|
TaskProperty: renderTask{
|
||||||
UnityRenderBeginTime: time.Now().UTC().UnixMilli(),
|
UnityRenderBeginTime: unityRenderBeginTime,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes))
|
logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes))
|
||||||
|
@ -423,20 +416,34 @@ func (w *wsConnectItem) operationRenderTask() {
|
||||||
case 0: //渲染结果回调,删除任务
|
case 0: //渲染结果回调,删除任务
|
||||||
//存在任务,则发送渲染结果给前端
|
//存在任务,则发送渲染结果给前端
|
||||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
||||||
CombineTakesTime := ""
|
CombineTakesTime := "0ms"
|
||||||
UnityRenderTakesTime := ""
|
UnityRenderTakesTime := "0ms"
|
||||||
if taskData.CombineBeginTime > 0 && taskData.CombineEndTime > 0 {
|
uploadCombineImageTakesTime := "0ms"
|
||||||
CombineTakesTime = fmt.Sprintf("耗时%dms", taskData.CombineEndTime-taskData.CombineBeginTime)
|
uploadUnityRenderImageTakesTime := "0ms"
|
||||||
|
//合图时间
|
||||||
|
if taskData.CombineTakesTime > 0 {
|
||||||
|
CombineTakesTime = fmt.Sprintf("%dms", taskData.CombineTakesTime)
|
||||||
}
|
}
|
||||||
|
//上传刀版图时间
|
||||||
|
if taskData.UploadCombineImageTakesTime > 0 {
|
||||||
|
uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.UploadCombineImageTakesTime)
|
||||||
|
}
|
||||||
|
//unity渲染时间
|
||||||
if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 {
|
if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 {
|
||||||
UnityRenderTakesTime = fmt.Sprintf("耗时%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime)
|
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime)
|
||||||
|
}
|
||||||
|
//上传unity渲染图耗时
|
||||||
|
if taskData.UploadUnityRenderImageTakesTime > 0 {
|
||||||
|
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.UploadUnityRenderImageTakesTime)
|
||||||
}
|
}
|
||||||
//发送到出口
|
//发送到出口
|
||||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
|
||||||
RenderId: taskData.RenderId,
|
RenderId: taskData.RenderId,
|
||||||
Image: data.RenderNotifyImageUrl,
|
Image: data.RenderNotifyImageUrl,
|
||||||
CombineTakesTime: CombineTakesTime,
|
CombineTakesTime: CombineTakesTime,
|
||||||
UnityRenderTakesTime: UnityRenderTakesTime,
|
UnityRenderTakesTime: UnityRenderTakesTime,
|
||||||
|
UploadCombineImageTakesTime: uploadCombineImageTakesTime,
|
||||||
|
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
//删除任务
|
//删除任务
|
||||||
|
@ -447,15 +454,23 @@ func (w *wsConnectItem) operationRenderTask() {
|
||||||
}
|
}
|
||||||
case 2: //修改(耗时)属性
|
case 2: //修改(耗时)属性
|
||||||
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
|
||||||
if data.TaskProperty.CombineBeginTime != 0 {
|
//合图耗时
|
||||||
taskData.CombineBeginTime = data.TaskProperty.CombineBeginTime
|
if data.TaskProperty.CombineTakesTime != 0 {
|
||||||
|
taskData.CombineTakesTime = data.TaskProperty.CombineTakesTime
|
||||||
}
|
}
|
||||||
if data.TaskProperty.CombineEndTime != 0 {
|
//上传合图耗时
|
||||||
taskData.CombineEndTime = data.TaskProperty.CombineEndTime
|
if data.TaskProperty.UploadCombineImageTakesTime != 0 {
|
||||||
|
taskData.UploadCombineImageTakesTime = data.TaskProperty.UploadCombineImageTakesTime
|
||||||
}
|
}
|
||||||
|
//上传渲染结果图耗时
|
||||||
|
if data.TaskProperty.UploadUnityRenderImageTakesTime != 0 {
|
||||||
|
taskData.UploadUnityRenderImageTakesTime = data.TaskProperty.UploadUnityRenderImageTakesTime
|
||||||
|
}
|
||||||
|
//发送unity时间
|
||||||
if data.TaskProperty.UnityRenderBeginTime != 0 {
|
if data.TaskProperty.UnityRenderBeginTime != 0 {
|
||||||
taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime
|
taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime
|
||||||
}
|
}
|
||||||
|
//收到unity返回的时间
|
||||||
if data.TaskProperty.UnityRenderEndTime != 0 {
|
if data.TaskProperty.UnityRenderEndTime != 0 {
|
||||||
taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime
|
taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,12 @@ type RenderData struct {
|
||||||
|
|
||||||
// websocket发送渲染完的数据
|
// websocket发送渲染完的数据
|
||||||
type RenderImageRspMsg struct {
|
type RenderImageRspMsg struct {
|
||||||
RenderId string `json:"render_id"` //渲染id
|
RenderId string `json:"render_id"` //渲染id
|
||||||
Image string `json:"image"` //渲染结果图片
|
Image string `json:"image"` //渲染结果图片
|
||||||
CombineTakesTime string `json:"combine_takes_time"` //合图需要时间
|
CombineTakesTime string `json:"combine_takes_time"` //合图需要时间
|
||||||
UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
|
UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
|
||||||
|
UploadCombineImageTakesTime string `json:"upload_combine_image_takes_time"` //上传刀版图耗时
|
||||||
|
UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间
|
||||||
}
|
}
|
||||||
type ThirdPartyLoginRspMsg struct {
|
type ThirdPartyLoginRspMsg struct {
|
||||||
//websocket三方登录的通知数据
|
//websocket三方登录的通知数据
|
||||||
|
|
Loading…
Reference in New Issue
Block a user