feat(governance): policy-driven ingestion from catalog annotations
Annotation in 来源与目录 is now the only import decision surface: - migration 000033: catalog_import_intents (durable, rescan-proof per-file intent with locator snapshot + fetch lifecycle), source_items.policy_state, planned publication state, ui_setting_revisions.ingestion_concurrency - marking fans a folder decision out to per-file intents, materializes versioned items, reuses already-verified local bytes (compare, don't pull), and plans one publication per routed KB; blocked retires planned rows while live publications stay untouched (需下架 shows in the KB diff) - artifact.fetch worker lane (scripts/artifact_fetch.py): DingTalk export tree/live box API, AList /api/fs/get direct download with SSO-redirect fail-closed, PP ledger via locator hash; content-level dedupe on sha256 - 开始处理 promotes planned->pending inside the claim-time concurrency budget from system settings; claims enforce it in SQL - monitor overview rebuilt as knowledge-base diff: planned/needs_removal per KB + fetch pipeline summary; frontend lanes 待入库/需下架 replace the deprecated snapshot change-set confirmation - spool: images (png/jpg/gif/bmp/webp) accepted, ppt/pptx rejected in favour of PDF twins; DingTalk PPT resolves its converted PDF pair
This commit is contained in:
@@ -16,9 +16,12 @@ func (s *Store) StartTestPublications(ctx context.Context, request governance.St
|
||||
result := governance.StartTestPublicationsResult{Selected: len(request.PublicationIDs)}
|
||||
operator := strings.TrimSpace(request.OperatorRef)
|
||||
reason := strings.TrimSpace(request.Reason)
|
||||
if len(request.PublicationIDs) == 0 || len(request.PublicationIDs) > 100 || operator == "" || len(operator) > 128 || reason == "" || len(reason) > 500 || request.Now.IsZero() {
|
||||
if len(request.PublicationIDs) == 0 || len(request.PublicationIDs) > 100 || operator == "" || len(operator) > 128 || len(reason) > 500 || request.Now.IsZero() {
|
||||
return governance.StartTestPublicationsResult{}, errors.New("invalid processing confirmation")
|
||||
}
|
||||
if reason == "" {
|
||||
reason = "开始处理"
|
||||
}
|
||||
seen := make(map[string]bool, len(request.PublicationIDs))
|
||||
for _, publicationID := range request.PublicationIDs {
|
||||
if !validRouteID(publicationID) || seen[publicationID] {
|
||||
@@ -50,22 +53,23 @@ func (s *Store) StartTestPublications(ctx context.Context, request governance.St
|
||||
|
||||
for _, publicationID := range request.PublicationIDs {
|
||||
var ready, confirmed, uploadJobExists bool
|
||||
var processingState string
|
||||
err = tx.QueryRow(ctx, `
|
||||
SELECT p.ingest_state='pending'
|
||||
AND p.processing_state='pending'
|
||||
AND p.retrieval_state='unpublished'
|
||||
AND p.knowledge_id=''
|
||||
AND version.content_state='verified'
|
||||
AND content.content_state='verified'
|
||||
AND content.local_spool_ref<>''
|
||||
AND content.size_bytes>0 AS ready,
|
||||
p.processing_state,
|
||||
EXISTS(SELECT 1 FROM processing_confirmations confirmation WHERE confirmation.publication_id=p.id),
|
||||
EXISTS(SELECT 1 FROM jobs job WHERE job.type='test.upload' AND job.payload->>'publication_id'=p.id)
|
||||
FROM test_publications p
|
||||
JOIN source_item_versions version ON version.id=p.source_item_version_id
|
||||
JOIN content_objects content ON content.id=version.content_object_id
|
||||
WHERE p.id=$1
|
||||
FOR UPDATE OF p`, publicationID).Scan(&ready, &confirmed, &uploadJobExists)
|
||||
WHERE p.id=$1 AND p.superseded_at IS NULL
|
||||
FOR UPDATE OF p`, publicationID).Scan(&ready, &processingState, &confirmed, &uploadJobExists)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
result.Unavailable++
|
||||
continue
|
||||
@@ -77,10 +81,18 @@ FOR UPDATE OF p`, publicationID).Scan(&ready, &confirmed, &uploadJobExists)
|
||||
result.AlreadyStarted++
|
||||
continue
|
||||
}
|
||||
// 开始处理 promotes both fresh plans and verified pending rows.
|
||||
if processingState != "planned" && processingState != "pending" {
|
||||
result.Unavailable++
|
||||
continue
|
||||
}
|
||||
if !ready {
|
||||
result.Unavailable++
|
||||
continue
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `UPDATE test_publications SET processing_state='pending',updated_at=$2 WHERE id=$1 AND processing_state='planned'`, publicationID, request.Now); err != nil {
|
||||
return governance.StartTestPublicationsResult{}, fmt.Errorf("promote planned publication: %w", err)
|
||||
}
|
||||
confirmationID, err := newOpaqueID("pc-")
|
||||
if err != nil {
|
||||
return governance.StartTestPublicationsResult{}, err
|
||||
|
||||
Reference in New Issue
Block a user