diff --git a/docs/architecture/worker-redis-queue-migration.md b/docs/architecture/worker-redis-queue-migration.md index 0130c877..d4e95304 100644 --- a/docs/architecture/worker-redis-queue-migration.md +++ b/docs/architecture/worker-redis-queue-migration.md @@ -320,10 +320,15 @@ func (wp *WorkerPool) processRedisMessage(ctx context.Context, msg redis.XMessag return } - // Claim 检查:防止多 consumer 竞争同一 job now := wp.now() + if err := archiveExhaustedRetries(wp.db.WithContext(ctx).Where("id = ?", jobID), now); err != nil { + applogger.L().Errorf("archive exhausted job %d failed: %v", jobID, err) + return + } + + // Claim 检查:防止多 consumer 竞争同一 job result := wp.db.WithContext(ctx).Model(&model.BackgroundJob{}). - Where("id = ? AND status IN ? AND scheduled_at <= ?", + Where("id = ? AND status IN ? AND scheduled_at <= ? AND attempts < max_attempts", jobID, []string{model.BackgroundJobStatusQueued, model.BackgroundJobStatusRetrying}, now,