优化切割逻辑,提前判断是否成功

This commit is contained in:
2025-04-13 14:41:29 +08:00
parent a478902f98
commit 37da5abad0
2 changed files with 70 additions and 14 deletions

View File

@ -11,7 +11,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"log"
"os"
"path"
)
@ -55,19 +54,6 @@ func HandleTask(ctx context.Context, device config.DeviceMapping, task dto.Task)
span.SetStatus(codes.Error, "ffmpeg任务执行失败")
return nil, fmt.Errorf("ffmpeg任务执行失败")
}
outfile, err := os.Stat(constructTask.OutputFile)
if err != nil {
span.SetAttributes(attribute.String("error", err.Error()))
span.SetStatus(codes.Error, "文件不存在")
return nil, fmt.Errorf("文件不存在:%s", constructTask.OutputFile)
}
span.SetAttributes(attribute.String("file.name", outfile.Name()))
span.SetAttributes(attribute.Int64("file.size", outfile.Size()))
if outfile.Size() < 4096 {
span.SetAttributes(attribute.String("error", "文件大小过小"))
span.SetStatus(codes.Error, "文件大小过小")
return nil, fmt.Errorf("文件大小过小:%s", constructTask.OutputFile)
}
return &dto.FileObject{
CreateTime: task.EndTime,
EndTime: task.EndTime,