mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-04 00:03:59 +00:00
feat(scheduler): M2 调度器骨架(就绪队列 + 选择函数 + 快照 + 任务级 panic 隔离)
设计依据 docs/zh/input-scheduler-design.md §14 M2。 - 新增 scheduler.go:四级 Level 常量(默认 L1,显式才是特权)、 Task/TaskKind、scheduler(有界队列/running/统计)、纯函数 pickTaskIndex (排序键 -Level → EnqueuedAt → ID)、schedulerLoop/pumpInbox/executeTask、 DumpScheduler 原子快照 - eventLoop 退场,职责由 schedulerLoop 承担;M2 全部任务为 L1, 因而行为等价于原先的 channel FIFO - 每任务 panic 隔离(不变量 I6):panic 只失败该任务,调度器存活, 取代原先「重启整个循环」 - Start() 改起 schedulerLoop;interceptLoop 暂不动(M3 重写) - 新增 scheduler_test.go:Q1 排序 4 组、Q4 背压、生命周期、K1 panic 隔离、 O1 快照一致性、Level 取值契约 - 验收:agent 全量 + -race 通过
This commit is contained in:
@ -13,25 +13,11 @@ import (
|
||||
pubsdk "gitcode.com/JianFeeeee/homeagent-sdk/sdk"
|
||||
)
|
||||
|
||||
func (a *Agent) eventLoop() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Printf("[agent] eventLoop panic recovered: %v\n%s", r, debug.Stack())
|
||||
time.Sleep(time.Second)
|
||||
go a.eventLoop()
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case evt := <-a.io.InputChan():
|
||||
a.handleInput(evt)
|
||||
case msg := <-a.selfInputCh:
|
||||
a.handleSelfInput(msg)
|
||||
case <-a.ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
// eventLoop 已由 scheduler.go 的 schedulerLoop 取代(M2)。
|
||||
//
|
||||
// 原实现直接在 select 里处理 inputCh/selfInputCh,没有任何可枚举的队列、
|
||||
// 无法承载优先级与抢占;现在任务先入就绪队列,由选择函数 pickTaskIndex 决定下一个。
|
||||
// 兼容性说明:M2 全部任务为 LevelBackground,因此行为等价于原先的 FIFO。
|
||||
|
||||
func (a *Agent) interceptLoop() {
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user