"librecover-"+窗口作业 id 超过 varchar(36),投递直接失败——恢复入口等于打不开。 按窗口摘要取 33 字符的确定性 id。
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user