将 Worker 发现、路由画像、容量与执行传输抽象为平台无关接口,新增 Kubernetes 和静态容量适配器,并以 shadow 模式接入生产配置。 实现网络与容量评分、路由防抖、池队列、同步 Worker 租约、一次性执行令牌,以及提交状态不明时禁止重复分配的安全语义。 新增 0105 兼容迁移、管理接口、指标、OpenAPI 和回归测试。已执行全量 Go 测试、go vet、OpenAPI、迁移安全、Compose 与 Kustomize 验证。
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package executionpool
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type RoutePreference struct {
|
|
RouteProfileKey string
|
|
CurrentPoolID string
|
|
CurrentSince time.Time
|
|
ChallengerPoolID string
|
|
ChallengerWins int
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func AdvanceRoutePreference(
|
|
previous RoutePreference,
|
|
proposedPoolID string,
|
|
scores map[string]float64,
|
|
now time.Time,
|
|
) RoutePreference {
|
|
if now.IsZero() {
|
|
now = time.Now()
|
|
}
|
|
proposedPoolID = strings.TrimSpace(proposedPoolID)
|
|
next := previous
|
|
next.UpdatedAt = now
|
|
if proposedPoolID == "" {
|
|
return next
|
|
}
|
|
if _, eligible := scores[next.CurrentPoolID]; next.CurrentPoolID == "" || !eligible {
|
|
next.CurrentPoolID = proposedPoolID
|
|
next.CurrentSince = now
|
|
next.ChallengerPoolID = ""
|
|
next.ChallengerWins = 0
|
|
return next
|
|
}
|
|
if proposedPoolID == next.CurrentPoolID {
|
|
next.ChallengerPoolID = ""
|
|
next.ChallengerWins = 0
|
|
return next
|
|
}
|
|
if relativeImprovement(scores[proposedPoolID], scores[next.CurrentPoolID]) < defaultSwitchImprovement {
|
|
next.ChallengerPoolID = ""
|
|
next.ChallengerWins = 0
|
|
return next
|
|
}
|
|
if next.ChallengerPoolID == proposedPoolID {
|
|
next.ChallengerWins++
|
|
} else {
|
|
next.ChallengerPoolID = proposedPoolID
|
|
next.ChallengerWins = 1
|
|
}
|
|
if next.ChallengerWins >= defaultBetterWindowCount &&
|
|
!next.CurrentSince.IsZero() && now.Sub(next.CurrentSince) >= defaultMinimumDwell {
|
|
next.CurrentPoolID = proposedPoolID
|
|
next.CurrentSince = now
|
|
next.ChallengerPoolID = ""
|
|
next.ChallengerWins = 0
|
|
}
|
|
return next
|
|
}
|