Compare commits
2 Commits
7f0e4fe607
...
73a7d26816
| Author | SHA1 | Date | |
|---|---|---|---|
| 73a7d26816 | |||
| 1cac9e9013 |
@@ -56,7 +56,7 @@ jobs:
|
|||||||
build_date=$(TZ=Asia/Shanghai date +"%Y%m%d%H%M")
|
build_date=$(TZ=Asia/Shanghai date +"%Y%m%d%H%M")
|
||||||
wails build \
|
wails build \
|
||||||
-platform windows/amd64 \
|
-platform windows/amd64 \
|
||||||
-ldflags "-X 'main.version=$build_date-$git_hash'" \
|
-ldflags "-X 'main.version= $build_date - $git_hash'" \
|
||||||
-o 上传工具.exe
|
-o 上传工具.exe
|
||||||
|
|
||||||
- name: 上传构建文件
|
- name: 上传构建文件
|
||||||
|
|||||||
+10
-1
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,7 +29,11 @@ func init() {
|
|||||||
|
|
||||||
// InitConn 创建连接池
|
// InitConn 创建连接池
|
||||||
func InitConn() {
|
func InitConn() {
|
||||||
for i := 0; i < 200; i++ {
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
wg.Go(func() {
|
||||||
|
for i := 0; i < 50; i++ {
|
||||||
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
|
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -39,6 +44,10 @@ func InitConn() {
|
|||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func UploadDataToServer(ctx context.Context, data string) error {
|
func UploadDataToServer(ctx context.Context, data string) error {
|
||||||
|
|||||||
@@ -211,7 +211,6 @@ func getTxtFiles(dir string) (txtFiles []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func processFile(ctx context.Context, logChan *chan string, filePath string, fileLines int) {
|
func processFile(ctx context.Context, logChan *chan string, filePath string, fileLines int) {
|
||||||
var wg sync.WaitGroup
|
|
||||||
// 打开文件
|
// 打开文件
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -221,8 +220,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
|
|||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// 创建行通道
|
// 创建行通道
|
||||||
lines := make(chan string, 100)
|
lines := make(chan string, 200)
|
||||||
defer close(lines)
|
|
||||||
var countLine int32 = 0
|
var countLine int32 = 0
|
||||||
// 创建指定个worker同时处理文件上传
|
// 创建指定个worker同时处理文件上传
|
||||||
for i := 0; i < config.APPConfig.ThreadCount; i++ {
|
for i := 0; i < config.APPConfig.ThreadCount; i++ {
|
||||||
@@ -230,9 +228,9 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
wg.Go(func() {
|
go func() {
|
||||||
processLines(ctx, logChan, &lines, i, filePath, &countLine)
|
processLines(ctx, logChan, &lines, i, filePath, &countLine)
|
||||||
})
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,22 +253,33 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// 等待所有行处理完成并推送进度
|
||||||
for int(countLine) != fileLines {
|
for int(countLine) != fileLines {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
wg.Wait()
|
close(lines) //关闭processLines中的上传线程
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
progress.Store(filepath.Base(filePath),
|
progress.Store(filepath.Base(filePath),
|
||||||
Progress{FileName: filepath.Base(filePath),
|
Progress{
|
||||||
Total: fileLines, Uploaded: int(countLine),
|
FileName: filepath.Base(filePath),
|
||||||
Percentage: int(float64(countLine)/float64(fileLines)*100) + 1,
|
Total: fileLines,
|
||||||
})
|
Uploaded: int(countLine),
|
||||||
time.Sleep(500 * time.Millisecond)
|
Percentage: int(float64(countLine) / float64(fileLines) * 100),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//上传完成,进度设为100
|
||||||
wg.Wait()
|
progress.Store(filepath.Base(filePath),
|
||||||
|
Progress{
|
||||||
|
FileName: filepath.Base(filePath),
|
||||||
|
Total: fileLines,
|
||||||
|
Uploaded: int(countLine),
|
||||||
|
Percentage: 100,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
close(lines) //关闭processLines中的上传线程
|
||||||
|
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
AddLog(logChan, fmt.Sprintf("读取文件 %s 错误: %v", filePath, err))
|
AddLog(logChan, fmt.Sprintf("读取文件 %s 错误: %v", filePath, err))
|
||||||
@@ -280,6 +289,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
|
|||||||
AddLog(logChan, fmt.Sprintf("文件【%s】处理完成,共处理 %d 行数据", filepath.Base(filePath), countLine))
|
AddLog(logChan, fmt.Sprintf("文件【%s】处理完成,共处理 %d 行数据", filepath.Base(filePath), countLine))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// processLines 处理接受到的每一行数据并上传(chan 管道接受数据)
|
||||||
func processLines(ctx context.Context, logChan *chan string, lines *chan string, workerID int, filePath string, countLine *int32) {
|
func processLines(ctx context.Context, logChan *chan string, lines *chan string, workerID int, filePath string, countLine *int32) {
|
||||||
for line := range *lines {
|
for line := range *lines {
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user