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