fix(wiki): Lite ingest lock, failed-op requeue, sync task retry parity
- Add per-KB sync.Map lock in Lite mode to mirror Redis SetNX concurrency. - Requeue failed wiki ops in Lite by enqueueing asynq tasks with delay/tracing. - Teach SyncTaskExecutor to honor ProcessIn delay and MaxRetry like Redis asynq.
This commit is contained in:
@@ -142,6 +142,14 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
}()
|
||||
} else {
|
||||
mode = "lite"
|
||||
// In-process mutual exclusion: mirrors the Redis SetNX lock above.
|
||||
if _, loaded := s.liteLocks.LoadOrStore(payload.KnowledgeBaseID, struct{}{}); loaded {
|
||||
exitStatus = "active_lock_conflict"
|
||||
logger.Infof(ctx, "wiki ingest: another batch active for KB %s (lite lock), deferring to asynq retry", payload.KnowledgeBaseID)
|
||||
return ErrWikiIngestConcurrent
|
||||
}
|
||||
lockAcquired = true
|
||||
defer s.liteLocks.Delete(payload.KnowledgeBaseID)
|
||||
}
|
||||
|
||||
kb, err := s.kbService.GetKnowledgeBaseByIDOnly(ctx, payload.KnowledgeBaseID)
|
||||
@@ -419,7 +427,7 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
// This must happen after trim: trim removes the consumed batch head, then
|
||||
// requeue appends the failed items to the tail for a future attempt.
|
||||
if len(failedOps) > 0 {
|
||||
s.requeueFailedOps(ctx, payload.KnowledgeBaseID, failedOps)
|
||||
s.requeueFailedOps(ctx, payload, failedOps)
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "wiki ingest: batch completed for KB %s, %d ops, %d pages affected", payload.KnowledgeBaseID, len(pendingOps), len(allPagesAffected))
|
||||
|
||||
Reference in New Issue
Block a user