refactor(uploader): 优化上传功能的上下文管理和并发控制
构建上传工具 / build-tool (push) Successful in 1m16s

- 在 UploadDataToServer 函数中添加 context 参数支持
- 使用 http.NewRequest 替换 httpClient.Post 以更好地控制请求上下文
- 重构应用启动逻辑,在 StartUpload 中初始化上传器上下文
- 优化 StopUpload 方法中的上下文取消机制
- 移除上传过程中的 wg.Wait() 调用以改善并发性能
This commit is contained in:
2026-04-27 13:38:14 +08:00
parent d44efeef8d
commit 987f0236a9
3 changed files with 14 additions and 6 deletions
+1 -2
View File
@@ -211,7 +211,6 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
select {
case <-ctx.Done():
close(lines)
wg.Wait()
return
default:
progress.Store(filepath.Base(filePath),
@@ -245,7 +244,7 @@ func processLines(ctx context.Context, logChan *chan string, lines *chan string,
continue
}
// 上传数据
if err := api.UploadDataToServer(line); err != nil {
if err := api.UploadDataToServer(ctx, line); err != nil {
AddLog(logChan, fmt.Sprintf("Worker %d (文件 %s): 上传失败: %v", workerID, filePath, err))
}
atomic.AddInt32(countLine, 1)