Skip to content

Commit

Permalink
perf: upload remain replays 10mins later
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Dec 11, 2024
1 parent 0dace0a commit 4019067
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
15 changes: 5 additions & 10 deletions cmd/common/uploader_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,25 @@ 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]
u.recordingSessionLifecycleReplay(remainReplay.Id, model.ReplayUploadStart, "")
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",
Expand All @@ -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
}

Expand Down
13 changes: 5 additions & 8 deletions cmd/impl/jms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4019067

Please sign in to comment.