feat: add a service for periodic cleanup of error accounts based on configuration.

This commit is contained in:
2026-02-01 06:02:39 +08:00
parent e867bc5cbd
commit 14a07e741e
5 changed files with 85 additions and 10 deletions

View File

@@ -89,13 +89,10 @@ func checkAndCleanErrors() {
}
if len(errorAccounts) == 0 {
logger.Info("没有错误账号需要清理", "", "cleaner")
lastCleanTime = time.Now()
return
}
logger.Info(fmt.Sprintf("找到 %d 个错误账号,开始删除...", len(errorAccounts)), "", "cleaner")
success := 0
failed := 0
@@ -106,7 +103,6 @@ func checkAndCleanErrors() {
logger.Warning(fmt.Sprintf("删除账号失败: ID=%d, Email=%s, Error=%v", account.ID, account.Email, err), account.Email, "cleaner")
} else {
success++
logger.Success(fmt.Sprintf("删除账号成功: ID=%d, Email=%s", account.ID, account.Email), account.Email, "cleaner")
}
}

View File

@@ -242,3 +242,22 @@ func ClearLogs() {
defer logsMu.Unlock()
logs = make([]LogEntry, 0, 1000)
}
// ClearLogsByModule 按模块清除日志
func ClearLogsByModule(module string) int {
logsMu.Lock()
defer logsMu.Unlock()
// 过滤掉指定模块的日志
var newLogs []LogEntry
cleared := 0
for _, log := range logs {
if log.Module != module {
newLogs = append(newLogs, log)
} else {
cleared++
}
}
logs = newLogs
return cleared
}