Enhance wiki ingest process to handle failed operations
- Introduced a mechanism to track and requeue failed operations during the wiki ingest process. - Added a new `requeueFailedOps` function to append failed operations back to the Redis pending list for retry in subsequent batches. - Updated the `ProcessWikiIngest` method to collect failed operations and ensure they are retried after trimming the pending list. This change improves the robustness of the ingest process by preventing data loss from transient failures.
This commit is contained in:
@@ -228,6 +228,7 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
|
||||
// 1. MAP PHASE (Parallel extraction and generation of updates)
|
||||
var mapMu sync.Mutex
|
||||
var failedOps []WikiPendingOp
|
||||
slugUpdates := make(map[string][]SlugUpdate)
|
||||
var docResults []*docIngestResult
|
||||
var retractChangeDesc strings.Builder
|
||||
@@ -310,6 +311,7 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
if err != nil {
|
||||
mapMu.Lock()
|
||||
ingestFailed++
|
||||
failedOps = append(failedOps, op)
|
||||
mapMu.Unlock()
|
||||
logger.Warnf(mapCtx, "wiki ingest: failed to map knowledge %s: %v", op.KnowledgeID, err)
|
||||
return nil // Don't fail the whole batch
|
||||
@@ -413,6 +415,13 @@ func (s *wikiIngestService) ProcessWikiIngest(ctx context.Context, t *asynq.Task
|
||||
|
||||
s.trimPendingList(ctx, payload.KnowledgeBaseID, peekedCount)
|
||||
|
||||
// Re-enqueue failed ops so they get retried in the next follow-up batch.
|
||||
// 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)
|
||||
}
|
||||
|
||||
logger.Infof(ctx, "wiki ingest: batch completed for KB %s, %d ops, %d pages affected", payload.KnowledgeBaseID, len(pendingOps), len(allPagesAffected))
|
||||
|
||||
followUpScheduled = s.scheduleFollowUp(ctx, payload)
|
||||
|
||||
Reference in New Issue
Block a user