fix(wiki-ingest,asynqdl): review fixups for PR #1241

- repo: drop r.db.Debug() from FindSimilarPages — it was dumping every
  trigram probe's SQL+args (per-alias, per-item) into production logs.
- wiki_ingest dedup: fix Printf format string ("selected for %d new
  items" had two args), and harden validMerge against un-prefixed
  slugs whose strings.Index returned -1 and silently passed the type
  check.
- wiki_ingest_batch: drop the duplicated loggedBatchSize/MapPar/
  ReducePar assignments.
- asynqdl: record the real attempt count (retried + 1) on the dead
  letter row instead of a hard-coded 0; tighten payloadProbe to the
  set of field names with consistent semantics across payloads
  (drop source_id/target_id/target_kb_id which differ by task type).
- asynqdl tests: update for the trimmed probe and assert FailCount=0
  outside an asynq worker ctx so the semantics stay pinned.
This commit is contained in:
wizardchen
2026-05-09 23:59:12 +08:00
committed by lyingbug
parent 04e8105728
commit 82947c726e
5 changed files with 63 additions and 35 deletions
+9 -4
View File
@@ -16,9 +16,9 @@ import (
// the subset of TaskDeadLetterRepository the middleware uses; the
// Lister methods are unused in the middleware path.
type fakeRepo struct {
mu sync.Mutex
rows []*types.TaskDeadLetter
fail error
mu sync.Mutex
rows []*types.TaskDeadLetter
fail error
}
func (f *fakeRepo) Insert(ctx context.Context, dl *types.TaskDeadLetter) error {
@@ -112,6 +112,11 @@ func TestMiddleware_FailureWithoutAsynqCtx_RecordsRow(t *testing.T) {
if row.LastError != "boom" {
t.Errorf("last_error: got %q", row.LastError)
}
// Outside an asynq worker ctx GetRetryCount returns !ok, so the
// middleware records 0 attempts (clearer than a misleading 1).
if row.FailCount != 0 {
t.Errorf("fail_count: expected 0 outside worker ctx, got %d", row.FailCount)
}
}
func TestMiddleware_UnknownPayload_StillRecords(t *testing.T) {
@@ -193,7 +198,7 @@ func TestInferScope_Priority(t *testing.T) {
},
{
name: "source_kb_id from KnowledgeMovePayload",
probe: payloadProbe{SourceKBID: "src-kb", TargetKBID: "tgt-kb"},
probe: payloadProbe{SourceKBID: "src-kb"},
wantScope: types.TaskScopeKnowledgeBase,
wantID: "src-kb",
},