fix(team_process): Clean up stuck processing owners on startup and batch completion
- Add CleanupStuckProcessingOwners database method to reset owners stuck in processing status back to valid state - Call cleanup routine on application startup to recover from previous abnormal exits - Call cleanup routine after batch processing completes to ensure no orphaned processing states remain - Add markOwnerResult calls in processSingleTeam when team invitations are full to properly track owner status - Prevents owners from being permanently stuck in processing state due to unexpected shutdowns or errors
This commit is contained in:
@@ -367,6 +367,13 @@ func runTeamProcess(req TeamProcessRequest) {
|
||||
defer func() {
|
||||
teamProcessState.Running = false
|
||||
|
||||
// 清理残留的 processing 状态母号,重置为 valid
|
||||
if database.Instance != nil {
|
||||
if affected, err := database.Instance.CleanupStuckProcessingOwners(); err == nil && affected > 0 {
|
||||
logger.Warning(fmt.Sprintf("批次结束,重置了 %d 个残留的处理中母号为有效状态", affected), "", "team")
|
||||
}
|
||||
}
|
||||
|
||||
// 无论任务是正常完成还是异常中断,都更新批次记录状态
|
||||
if database.Instance != nil && batchID > 0 {
|
||||
errorsStr := ""
|
||||
@@ -993,6 +1000,7 @@ func processSingleTeam(idx int, req TeamProcessRequest) (result TeamProcessResul
|
||||
result.AddedToS2A = int(atomic.LoadInt32(&s2aSuccessCount))
|
||||
result.Errors = append(result.Errors, "Team 邀请已满")
|
||||
result.DurationMs = time.Since(startTime).Milliseconds()
|
||||
markOwnerResult(result.AddedToS2A > 0)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1027,6 +1035,7 @@ func processSingleTeam(idx int, req TeamProcessRequest) (result TeamProcessResul
|
||||
result.AddedToS2A = int(atomic.LoadInt32(&s2aSuccessCount))
|
||||
result.Errors = append(result.Errors, "Team 邀请已满")
|
||||
result.DurationMs = time.Since(startTime).Milliseconds()
|
||||
markOwnerResult(result.AddedToS2A > 0)
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user