fix(library): 恢复作业的队列 id 不能超过列宽
build / build (push) Successful in 1m15s

"librecover-"+窗口作业 id 超过 varchar(36),投递直接失败——恢复入口等于打不开。
按窗口摘要取 33 字符的确定性 id。
This commit is contained in:
姚章浩
2026-10-29 01:07:11 +08:00
parent 5afe151c7d
commit 1a04dfb4fa
+6 -1
View File
@@ -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 {