feat(monitor): 死信中文提示与成功/取消自动退信
This commit is contained in:
@@ -134,15 +134,28 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
|
||||
return jobs.Permanent(jobs.ErrCodeArtifactInvalid, ErrUploadArtifactInvalid)
|
||||
}
|
||||
if uploadErr != nil {
|
||||
if !errors.Is(uploadErr, weknora.ErrConflict) && !weknora.IsRetryable(uploadErr) {
|
||||
return ErrUploadRemoteFailed
|
||||
}
|
||||
knowledge, err = handler.recoverAmbiguousUpload(ctx, candidate)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrUploadRemoteIdentity) {
|
||||
return handler.recordTerminalUploadFailure(ctx, candidate.ID, "upload_identity_ambiguous")
|
||||
if errors.Is(uploadErr, weknora.ErrConflict) && knowledge.ID != "" {
|
||||
// WeKnora dedupes identical file bytes across publications: when the
|
||||
// same document was already uploaded under a sibling publication (the
|
||||
// same file living in two source folders), the conflict response names
|
||||
// the existing item. Adopt it instead of dead-lettering forever.
|
||||
if verified, verifyErr := handler.client.GetKnowledge(ctx, knowledge.ID); verifyErr == nil &&
|
||||
verified.ID == knowledge.ID && verified.KnowledgeBaseID == candidate.TestKBID &&
|
||||
shaMatches(verified, candidate.SHA256) {
|
||||
knowledge = verified
|
||||
} else {
|
||||
return ErrUploadRemoteFailed
|
||||
}
|
||||
} else if !errors.Is(uploadErr, weknora.ErrConflict) && !weknora.IsRetryable(uploadErr) {
|
||||
return ErrUploadRemoteFailed
|
||||
} else {
|
||||
knowledge, err = handler.recoverAmbiguousUpload(ctx, candidate)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrUploadRemoteIdentity) {
|
||||
return handler.recordTerminalUploadFailure(ctx, candidate.ID, "upload_identity_ambiguous")
|
||||
}
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
if knowledge.ID == "" || knowledge.KnowledgeBaseID != candidate.TestKBID {
|
||||
@@ -201,6 +214,15 @@ func metadataString(metadata map[string]any, key string) (string, bool) {
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// shaMatches reports whether a remote item carries our content hash, either in
|
||||
// its metadata (uploads through governance) or as its file hash.
|
||||
func shaMatches(item weknora.Knowledge, sha string) bool {
|
||||
if value, ok := metadataString(item.Metadata, "content_sha256"); ok && value == sha {
|
||||
return true
|
||||
}
|
||||
return sha != "" && strings.EqualFold(item.FileHash, sha)
|
||||
}
|
||||
|
||||
func (handler *UploadHandler) recordTerminalUploadFailure(ctx context.Context, publicationID, code string) error {
|
||||
if err := handler.store.RecordUploadFailure(ctx, publicationID, code, handler.now()); err != nil {
|
||||
return ErrUploadStateConflict
|
||||
|
||||
Reference in New Issue
Block a user