feat: Initialize core application structure with backend configuration, database, API, and a comprehensive frontend UI for account pooling and management.
This commit is contained in:
@@ -179,10 +179,6 @@ func HandleTeamProcessStop(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// runTeamProcess 执行 Team 批量处理 - 使用工作池模式
|
||||
func runTeamProcess(req TeamProcessRequest) {
|
||||
defer func() {
|
||||
teamProcessState.Running = false
|
||||
}()
|
||||
|
||||
totalOwners := len(req.Owners)
|
||||
workerCount := req.ConcurrentTeams // 同时运行的 worker 数量
|
||||
if workerCount > totalOwners {
|
||||
@@ -202,6 +198,30 @@ func runTeamProcess(req TeamProcessRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// 统计变量(在 defer 中使用)
|
||||
var totalRegistered, totalAddedToS2A int
|
||||
var allErrors []string
|
||||
|
||||
// 确保任务结束时更新状态和批次记录
|
||||
defer func() {
|
||||
teamProcessState.Running = false
|
||||
|
||||
// 无论任务是正常完成还是异常中断,都更新批次记录状态
|
||||
if database.Instance != nil && batchID > 0 {
|
||||
errorsStr := ""
|
||||
if len(allErrors) > 0 {
|
||||
// 只保留前10条错误
|
||||
if len(allErrors) > 10 {
|
||||
allErrors = allErrors[:10]
|
||||
}
|
||||
errorsStr = fmt.Sprintf("%v", allErrors)
|
||||
}
|
||||
if err := database.Instance.UpdateBatchRun(batchID, totalRegistered, totalAddedToS2A, errorsStr); err != nil {
|
||||
logger.Error(fmt.Sprintf("更新批次记录失败: %v", err), "", "team")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
logger.Info(fmt.Sprintf("开始批量处理: 共 %d 个 Team, 并发数: %d", totalOwners, workerCount), "", "team")
|
||||
|
||||
// 任务队列
|
||||
@@ -243,10 +263,7 @@ func runTeamProcess(req TeamProcessRequest) {
|
||||
close(resultChan)
|
||||
}()
|
||||
|
||||
// 统计总数
|
||||
var totalRegistered, totalAddedToS2A int
|
||||
var allErrors []string
|
||||
|
||||
// 收集结果并统计
|
||||
for result := range resultChan {
|
||||
teamProcessState.mu.Lock()
|
||||
teamProcessState.Results = append(teamProcessState.Results, result)
|
||||
@@ -257,19 +274,6 @@ func runTeamProcess(req TeamProcessRequest) {
|
||||
allErrors = append(allErrors, result.Errors...)
|
||||
}
|
||||
|
||||
// 更新批次记录
|
||||
if database.Instance != nil && batchID > 0 {
|
||||
errorsStr := ""
|
||||
if len(allErrors) > 0 {
|
||||
// 只保留前10条错误
|
||||
if len(allErrors) > 10 {
|
||||
allErrors = allErrors[:10]
|
||||
}
|
||||
errorsStr = fmt.Sprintf("%v", allErrors)
|
||||
}
|
||||
database.Instance.UpdateBatchRun(batchID, totalRegistered, totalAddedToS2A, errorsStr)
|
||||
}
|
||||
|
||||
// 计算成功率
|
||||
expectedTotal := totalOwners * req.MembersPerTeam
|
||||
successRate := float64(0)
|
||||
|
||||
Reference in New Issue
Block a user