docs(HH-626): align Redis claim retry semantics (#171)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 17:01:17 +08:00
committed by GitHub
co-authored by rogee
parent 4455f8938d
commit df83d04ce6
@@ -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,