From 1a04dfb4faf2e0ac4e76a63c89c9e32d384c3fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Thu, 29 Oct 2026 01:07:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(library):=20=E6=81=A2=E5=A4=8D=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E7=9A=84=E9=98=9F=E5=88=97=20id=20=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=B6=85=E8=BF=87=E5=88=97=E5=AE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "librecover-"+窗口作业 id 超过 varchar(36),投递直接失败——恢复入口等于打不开。 按窗口摘要取 33 字符的确定性 id。 --- internal/httpapi/library_flow.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/httpapi/library_flow.go b/internal/httpapi/library_flow.go index b3e1d16..c2aa4fb 100644 --- a/internal/httpapi/library_flow.go +++ b/internal/httpapi/library_flow.go @@ -2,6 +2,8 @@ package httpapi import ( "context" + "crypto/sha256" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -376,8 +378,11 @@ func libraryMaintenanceRecoverHandler(w http.ResponseWriter, r *http.Request, co return } // 队列作业 id 与幂等键都按窗口固定:重复点击只会得到同一个恢复作业。 + // 队列 id 有长度上限(36),窗口作业 id 比它还长,所以按窗口摘要取短 id。 + sum := sha256.Sum256([]byte(held.OwnerJobID)) + queueID := "lrec-" + hex.EncodeToString(sum[:14]) queueJob, err := config.Store.Enqueue(r.Context(), jobs.EnqueueRequest{ - ID: "librecover-" + held.OwnerJobID, Type: libraryRecoverJobType, Payload: payload, + ID: queueID, Type: libraryRecoverJobType, Payload: payload, AvailableAt: now, MaxAttempts: 1, IdempotencyKey: "library.recover:" + held.OwnerJobID, }, now) if err != nil || queueJob == nil {