Version: 0.9.76.dev.260505
后端: 1.阶段 6 agent / memory 服务化收口 - 新增 cmd/agent 独立进程入口,承载 agent zrpc server、agent outbox relay / consumer 和运行时依赖初始化 - 补齐 services/agent/rpc 的 Chat stream 与 conversation meta/list/timeline、schedule-preview、context-stats、schedule-state unary RPC - 新增 gateway/client/agent 与 shared/contracts/agent,将 /api/v1/agent chat 和非 chat 门面切到 agent zrpc - 收缩 gateway 本地 AgentService 装配,双 RPC 开关开启时不再初始化本地 agent 编排、LLM、RAG 和 memory reader fallback - 将 backend/memory 物理迁入 services/memory,私有实现收入 internal,保留 module/model/observe 作为 memory 服务门面 - 调整 memory outbox、memory reader 和 agent 记忆渲染链路的 import 与服务边界,cmd/memory 独占 memory worker / consumer - 关闭 gateway 侧 agent outbox worker 所有权,agent relay / consumer 由 cmd/agent 独占,gateway 仅保留 HTTP/SSE 门面与迁移期开关回退 - 更新阶段 6 文档,记录 agent / memory 当前切流点、smoke 结果,以及 backend/client 与 gateway/shared 的目录收口口径
This commit is contained in:
56
backend/services/memory/internal/worker/loop.go
Normal file
56
backend/services/memory/internal/worker/loop.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package worker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RunPollingLoop 持续轮询 memory_jobs,把异步 worker 真正跑起来。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 这里只负责“循环 + 轮询频率 + 批量触发”;
|
||||
// 2. 不负责抽取逻辑,也不负责落库逻辑;
|
||||
// 3. 任意一次 RunOnce 报错时只打日志并继续下一轮,避免整个后台循环退出。
|
||||
func RunPollingLoop(ctx context.Context, runner *Runner, pollEvery time.Duration, claimBatch int) {
|
||||
if runner == nil {
|
||||
return
|
||||
}
|
||||
if runner.logger == nil {
|
||||
runner.logger = log.Default()
|
||||
}
|
||||
if pollEvery <= 0 {
|
||||
pollEvery = 2 * time.Second
|
||||
}
|
||||
if claimBatch <= 0 {
|
||||
claimBatch = 1
|
||||
}
|
||||
|
||||
runBatch := func() {
|
||||
for i := 0; i < claimBatch; i++ {
|
||||
result, err := runner.RunOnce(ctx)
|
||||
if err != nil {
|
||||
runner.logger.Printf("memory worker loop run once failed: %v", err)
|
||||
return
|
||||
}
|
||||
if result == nil || !result.Claimed {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runBatch()
|
||||
|
||||
ticker := time.NewTicker(pollEvery)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
runner.logger.Printf("memory worker loop stopped: %v", ctx.Err())
|
||||
return
|
||||
case <-ticker.C:
|
||||
runBatch()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user