From 927111d7a1cb723ce507eb2d817132d6e1388cfc Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 14 Nov 2024 18:25:27 +0800 Subject: [PATCH] perf: upload remain replays 10mins later --- cmd/common/uploader_service.go | 15 +++++---------- cmd/impl/jms.go | 13 +++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/cmd/common/uploader_service.go b/cmd/common/uploader_service.go index ea6e1a8..8bd4eb3 100644 --- a/cmd/common/uploader_service.go +++ b/cmd/common/uploader_service.go @@ -208,14 +208,13 @@ func (u *UploaderService) UploadCommand(cmd *model.Command) { u.commandChan <- cmd } -func (u *UploaderService) UploadRemainReplays(replayDir string) (ret RemainReplayResult) { +func (u *UploaderService) UploadRemainReplays(replayDir string) { allRemainReplays := scanRemainReplays(u.apiClient, replayDir) if len(allRemainReplays) <= 0 { return } - successFiles := make([]string, 0, 10) - failureFiles := make([]string, 0, 10) - failureErrs := make([]string, 0, 10) + logger.Infof("Start to upload %d replay files 10 min later", len(allRemainReplays)) + time.Sleep(10 * time.Minute) logger.Debugf("Upload Remain %d replay files", len(allRemainReplays)) for replayPath := range allRemainReplays { remainReplay := allRemainReplays[replayPath] @@ -223,13 +222,11 @@ func (u *UploaderService) UploadRemainReplays(replayDir string) (ret RemainRepla if err := u.uploadRemainReplay(&remainReplay); err != nil { logger.Errorf("Uploader service clean remain replay %s failed: %s", replayPath, err) - failureFiles = append(failureFiles, replayPath) - failureErrs = append(failureErrs, err.Error()) u.recordingSessionLifecycleReplay(remainReplay.Id, model.ReplayUploadFailure, err.Error()) continue } u.recordingSessionLifecycleReplay(remainReplay.Id, model.ReplayUploadSuccess, "") - successFiles = append(successFiles, replayPath) + logger.Infof("Uploader service upload replay %s success", replayPath) // 上传完成 删除原录像文件 if err := os.Remove(replayPath); err != nil { logger.Errorf("Uploader service clean remain replay %s failed: %s", @@ -240,9 +237,7 @@ func (u *UploaderService) UploadRemainReplays(replayDir string) (ret RemainRepla remainReplay.Id, err) } } - ret.FailureErrs = failureErrs - ret.FailureFiles = failureFiles - ret.SuccessFiles = successFiles + logger.Infof("Uploader service upload remain replay files done") return } diff --git a/cmd/impl/jms.go b/cmd/impl/jms.go index f4f03c8..b6b652d 100644 --- a/cmd/impl/jms.go +++ b/cmd/impl/jms.go @@ -169,16 +169,13 @@ func (j *JMServer) DispatchTask(stream pb.Service_DispatchTaskServer) error { func (j *JMServer) ScanRemainReplays(ctx context.Context, req *pb.RemainReplayRequest) (*pb.RemainReplayResponse, error) { status := pb.Status{Ok: true} - ret := j.uploader.UploadRemainReplays(req.GetReplayDir()) - if len(ret.FailureErrs) > 0 { - status.Ok = false - status.Err = fmt.Sprintf("there are %d errs in FailureErrs", len(ret.FailureErrs)) - } + relayDir := req.GetReplayDir() + go j.uploader.UploadRemainReplays(relayDir) return &pb.RemainReplayResponse{ Status: &status, - SuccessFiles: ret.SuccessFiles, - FailureFiles: ret.FailureFiles, - FailureErrs: ret.FailureErrs, + SuccessFiles: []string{}, + FailureFiles: []string{}, + FailureErrs: []string{}, }, nil }