F01:新增 /api/v1/system/worker-capabilities,按 job_types 判定 test.upload 执行器是否注册, 服务卡片分「地址可达 / 凭据与库读取 / 执行器能力」三行。 F04:routing-bindings 返回 LIBRARY_SOURCE_KB_* 与一致性,设置页同屏显示入库目标与封存源。 结构:测试绑定与生产目标合并为「知识库映射」。
This commit is contained in:
@@ -108,7 +108,13 @@ func (handler *PollHandler) Handle(ctx context.Context, job jobs.Job) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
cutoff := now.Add(-handler.stallAfter)
|
||||
stall := handler.stallAfter
|
||||
if handler.stallAfterSource != nil {
|
||||
if fromSettings := handler.stallAfterSource(); fromSettings > 0 {
|
||||
stall = fromSettings
|
||||
}
|
||||
}
|
||||
cutoff := now.Add(-stall)
|
||||
lastProgress := publication.LastProgressAt
|
||||
if lastProgress == nil {
|
||||
lastProgress = publication.ProcessingStartedAt
|
||||
|
||||
@@ -186,3 +186,61 @@ func (store *pollStoreStub) MarkStalled(_ context.Context, _ string, _ int, cuto
|
||||
store.stalledCutoff = cutoff
|
||||
return nil
|
||||
}
|
||||
|
||||
// F02 验收:停滞判定必须用“活动配置”的阈值,而不是启动时的常量。
|
||||
// 同一条已经停在同一进度上的解析任务:阈值 30 分钟判停,阈值 2 小时不判停。
|
||||
func TestPollHandlerStallThresholdFollowsActiveSettings(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"knowledge-1","knowledge_base_id":"kb-1","parse_status":"processing","updated_at":"2026-09-04T03:00:00Z"}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: server.URL, APIKey: "test-key", Timeout: time.Second})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Date(2026, time.September, 4, 4, 0, 0, 0, time.UTC)
|
||||
progressAt := now.Add(-45 * time.Minute)
|
||||
makeStore := func() *pollStoreStub {
|
||||
return &pollStoreStub{publication: postgresstore.PublicationForPoll{
|
||||
ID: "publication-1", TestKBID: "kb-1", KnowledgeID: "knowledge-1",
|
||||
ProcessingState: governance.ProcessingProcessing, PollSequence: 3,
|
||||
LastProgressAt: &progressAt, ProcessingStartedAt: &progressAt,
|
||||
}}
|
||||
}
|
||||
payload := jobs.Job{Payload: []byte(`{"publication_id":"publication-1","sequence":3}`)}
|
||||
|
||||
// 启动常量 30 分钟、活动配置也是 30 分钟:45 分钟没进度 → 判停。
|
||||
store := makeStore()
|
||||
handler, err := NewPollHandler(PollHandlerConfig{
|
||||
Store: store, Client: client, PollDelay: 15 * time.Second,
|
||||
StallAfter: 30 * time.Minute, Now: func() time.Time { return now },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := handler.Handle(context.Background(), payload); err != nil {
|
||||
t.Fatalf("Handle() error = %v", err)
|
||||
}
|
||||
if !store.stalledMarked {
|
||||
t.Fatal("30 分钟阈值下 45 分钟无进度应判停")
|
||||
}
|
||||
|
||||
// 活动配置改成 2 小时:同一条任务不应再判停。
|
||||
store = makeStore()
|
||||
handler, err = NewPollHandler(PollHandlerConfig{
|
||||
Store: store, Client: client, PollDelay: 15 * time.Second,
|
||||
StallAfter: 30 * time.Minute,
|
||||
StallAfterSource: func() time.Duration { return 2 * time.Hour },
|
||||
Now: func() time.Time { return now },
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := handler.Handle(context.Background(), payload); err != nil {
|
||||
t.Fatalf("Handle() error = %v", err)
|
||||
}
|
||||
if store.stalledMarked {
|
||||
t.Fatal("活动配置 2 小时阈值下不应判停:阈值没有接入实际判定")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user