feat(reconciliation): 实现导入对账后端
为什么:T6a 需要一张批次/差异表、全量只读扫描、R1-R8 判定和 finding 级处置;现有解析监控只转述台账状态,无法回答库内是否一致。 做什么:迁移 000084(upload_md5、runs/findings/actions、共享 removal_candidates 视图);WeKnora 字段与 1000/页扫描;runtime 只读客户端(0400 Key、503 降级);扫描/矩阵/动作/定时/僵死回收;9 条接口与 RBAC;overview 队列与删两张常量卡。 边界:只对测试库;对账零写请求;R1/R2 单条确认;R6 复用 /removal;R2 只管理员;生产链路未改。 验证:make verify 全绿(17 项);新增矩阵/扫描 R1-R8/零写/失败整批/动作/运行时/密钥权限测试。
This commit is contained in:
+54
-2
@@ -27,6 +27,7 @@ import (
|
||||
postgresstore "knowledge-governance/internal/platform/postgres"
|
||||
"knowledge-governance/internal/platform/weknora"
|
||||
"knowledge-governance/internal/readiness"
|
||||
"knowledge-governance/internal/reconciliation"
|
||||
"knowledge-governance/internal/versionhistory"
|
||||
"knowledge-governance/internal/weknoraaccess"
|
||||
artifactfetch "knowledge-governance/internal/workflows/artifactfetch"
|
||||
@@ -260,7 +261,44 @@ func run(ctx context.Context, getenv func(string) string) error {
|
||||
} else if repaired > 0 {
|
||||
log.Printf("library job reconcile: %d orphan job(s) marked failed", repaired)
|
||||
}
|
||||
handlers, err := workerHandlers(store, config, kbBindings)
|
||||
var reconciliationService *reconciliation.Service
|
||||
if config.TestWeKnoraEnabled && config.LibraryWorkerRole.ExecutesSourceWork() {
|
||||
reconciliationRemote := &weknoraaccess.Client{
|
||||
Resolver: readiness.Resolver{
|
||||
LoadBinding: func(resolveCtx context.Context) (string, error) {
|
||||
internal, _, _, bindingErr := store.LoadRoutingKBBindings(resolveCtx)
|
||||
return internal, bindingErr
|
||||
},
|
||||
ResolveConnection: func(resolveCtx context.Context) (string, string, error) {
|
||||
if kbBindings != nil {
|
||||
target, resolveErr := kbBindings.Resolve(resolveCtx, kbbinding.EnvTest)
|
||||
return target.BaseURL, target.APIKey, resolveErr
|
||||
}
|
||||
key, keyErr := weknora.ReadAPIKeyFile(config.TestWeKnoraAPIKeyFile)
|
||||
return config.TestWeKnoraBaseURL, key, keyErr
|
||||
},
|
||||
DefaultKB: config.InternalRoutingKnowledgeBaseID,
|
||||
},
|
||||
Timeout: config.TestWeKnoraHTTPTimeout,
|
||||
AllowDockerHTTP: config.TestWeKnoraAllowDockerHTTP,
|
||||
AllowPrivateHTTP: config.WeKnoraAllowPrivateHTTP,
|
||||
}
|
||||
reconciliationService, err = reconciliation.New(reconciliation.Config{
|
||||
Store: store,
|
||||
Remote: reconciliationRemote,
|
||||
Queue: store,
|
||||
Grace: config.ReconciliationGrace,
|
||||
StallAfter: config.ReconciliationStallAfter,
|
||||
StaleAfter: config.ReconciliationStaleAfter,
|
||||
ConfirmConcurrency: config.ReconciliationConfirmConcurrency,
|
||||
KeepRuns: config.ReconciliationKeepRuns,
|
||||
MaxAge: config.ReconciliationMaxAge,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
handlers, err := workerHandlers(store, config, kbBindings, reconciliationService)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -331,6 +369,9 @@ func run(ctx context.Context, getenv func(string) string) error {
|
||||
go runSourceRefreshScheduler(ctx, store, config.SourceRefreshSchedulerInterval, func(err error) {
|
||||
log.Printf("worker %s source refresh scheduler error: %v", config.WorkerID, err)
|
||||
})
|
||||
if reconciliationService != nil {
|
||||
go runReconciliationScheduler(ctx, store, reconciliationService, config)
|
||||
}
|
||||
}
|
||||
log.Printf("worker %s started role=%s release=%t source=%t (source refresh scheduler every %s)",
|
||||
config.WorkerID, config.LibraryWorkerRole, config.LibraryWorkerRole.ExecutesRelease(),
|
||||
@@ -373,7 +414,7 @@ func completeLibraryCaptureJob(ctx context.Context, store libraryCapturePersiste
|
||||
return nil
|
||||
}
|
||||
|
||||
func workerHandlers(store *postgresstore.Store, config appconfig.Config, kbBindings *kbbinding.Store) (map[string]jobs.Handler, error) {
|
||||
func workerHandlers(store *postgresstore.Store, config appconfig.Config, kbBindings *kbbinding.Store, reconciliationService *reconciliation.Service) (map[string]jobs.Handler, error) {
|
||||
handlers := map[string]jobs.Handler{
|
||||
"demo": func(_ context.Context, job jobs.Job) error {
|
||||
log.Printf("completed demo job id=%s", job.ID)
|
||||
@@ -648,6 +689,17 @@ func workerHandlers(store *postgresstore.Store, config appconfig.Config, kbBindi
|
||||
handlers["test.poll"] = poll.Handle
|
||||
handlers["test.validate"] = validate.Handle
|
||||
handlers["test.remove"] = remove.Handle
|
||||
if reconciliationService != nil {
|
||||
handlers["reconciliation.run"] = func(handlerCtx context.Context, job jobs.Job) error {
|
||||
var payload struct {
|
||||
RunID string `json:"run_id"`
|
||||
}
|
||||
if err := json.Unmarshal(job.Payload, &payload); err != nil || payload.RunID == "" {
|
||||
return jobs.Permanent(jobs.ErrCodeHandlerFallback, errors.New("invalid reconciliation run payload"))
|
||||
}
|
||||
return reconciliationService.ExecuteRun(handlerCtx, payload.RunID)
|
||||
}
|
||||
}
|
||||
return handlers, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user