fix(reconciliation): 对账任务入队 id 超长导致每批 queue_unavailable
build / build (push) Successful in 2m18s

enqueueRun 用 "job-" + run_id 当 jobs.id,而 jobs.id 是 VARCHAR(36);run_id 本身
已是 36 字符(rec- + 32 位 hex),拼出 40 字符,INSERT 必然失败,批次在 claim 之后
立刻被记成 failed/queue_unavailable——候选库里 19:37 起所有批次都是这个状态,C-101
起的用例全部无法开始。

改为 job 自带 "job-"+32 位 hex 的 id(36 字符),幂等仍由唯一 idempotency_key
(reconciliation-run:<run_id>)保证。补单测:CreateRun 入队请求 id 必须正好 36 字符、
type/idempotency_key/payload 与 run 一致。

验证:go test ./internal/reconciliation/ 通过;make verify 17 项 = 16 success + identity skipped。
This commit is contained in:
2026-12-01 19:47:00 +08:00
committed by zheromiku
parent f4b3f4c4c8
commit fe7edea1a3
2 changed files with 50 additions and 1 deletions
+8 -1
View File
@@ -214,8 +214,15 @@ func (s *Service) enqueueRun(ctx context.Context, runID string, now time.Time) e
if err != nil {
return err
}
// jobs.id is VARCHAR(36) and the run id alone already fills it ("rec-" + 32 hex),
// so the job carries its own id; idempotency is guaranteed by the unique
// idempotency_key below, not by deriving the id from the run.
jobID, err := newID("job-")
if err != nil {
return err
}
_, err = s.queue.Enqueue(ctx, jobs.EnqueueRequest{
ID: "job-" + runID,
ID: jobID,
Type: "reconciliation.run",
Payload: payload,
Priority: 5,