feat: add bounded task priority and fair application dispatch

This commit is contained in:
2026-09-17 18:45:54 +08:00
parent 958b4a8cea
commit 309ed75666
42 changed files with 1277 additions and 61 deletions

View File

@@ -43,8 +43,10 @@ type Task struct {
OwnerKind *string `db:"owner_kind"`
// OwnerID 来源资源标识,必须与来源类型同时有值或同时为空。
OwnerID *core.ID `db:"owner_id"`
// Priority 同一调度范围内的优先级,不承诺跨队列全局顺序。
// Priority 冻结优先级,0至9,每级30秒排序优势;不提前最早执行时间。
Priority int16 `db:"priority"`
// DispatchAt 数据库生成的排序时间,AvailableAt 减 Priority 乘30秒;只读,不是执行授权。
DispatchAt time.Time `db:"dispatch_at"`
// AvailableAt 最早可被领取或处理的时间,统一 UTC。
AvailableAt time.Time `db:"available_at"`
// StartDeadlineAt 最晚允许新尝试开始的时间;为空时仅受总时限约束。

View File

@@ -55,6 +55,9 @@ func NormalizeSubmit(in SubmitInput) (SubmitInput, error) {
if err := ValidateConcurrencyKey(in.ConcurrencyKey); err != nil {
return in, err
}
if in.Priority < 0 || in.Priority > 9 {
return in, fault.Invalid("priority must be between 0 and 9")
}
if in.TaskTimeoutMS == 0 {
in.TaskTimeoutMS = 24 * 60 * 60 * 1000
}

View File

@@ -27,6 +27,8 @@ type SubmitInput struct {
BusinessKey string `json:"business_key,omitempty"`
// ConcurrencyKey 显式互斥资源键,同命名空间跨队列最多一个有效尝试;不代替业务幂等。
ConcurrencyKey string `json:"concurrency_key,omitempty"`
// Priority 冻结优先级,0至9,每级30秒排序优势,不改变最早执行时间。
Priority int16 `json:"priority,omitempty"`
// AvailableAt 最早执行时间;为空表示受理后即可进入派发范围。
AvailableAt *time.Time `json:"available_at,omitempty"`
// StartDeadlineAt 最晚开始时间;为空表示使用任务总截止时间。
@@ -67,6 +69,8 @@ type TaskView struct {
BusinessKey string `json:"business_key,omitempty"`
// ConcurrencyKey 显式互斥资源键,同命名空间跨队列最多一个有效尝试;不代替业务幂等。
ConcurrencyKey string `json:"concurrency_key,omitempty"`
// Priority 冻结优先级,0至9,每级30秒排序优势,不改变最早执行时间。
Priority int16 `json:"priority,omitempty"`
// AvailableAt 最早可执行时间,UTC。
AvailableAt time.Time `json:"available_at"`
// StartDeadlineAt 最晚开始时间;为空时使用任务总截止时间。
@@ -137,6 +141,8 @@ type TaskSummary struct {
BusinessKey string `json:"business_key,omitempty"`
// ConcurrencyKey 显式互斥资源键,同命名空间跨队列最多一个有效尝试;不代替业务幂等。
ConcurrencyKey string `json:"concurrency_key,omitempty"`
// Priority 冻结优先级,0至9,每级30秒排序优势,不改变最早执行时间。
Priority int16 `json:"priority,omitempty"`
// AvailableAt 最早可执行时间,UTC。
AvailableAt time.Time `json:"available_at"`
// DeadlineAt 任务总截止时间,UTC。

View File

@@ -32,10 +32,11 @@ type ConnectInput struct {
// Binding 是接入层持有的认证结果,不作为公开请求字段接受或写入日志。
type Binding struct {
InstanceID core.ID // InstanceID 已证明秘密的进程标识。
SessionID core.ID // SessionID 当前连接标识。
Epoch uint64 // Epoch 连接代次。
Proof core.Digest // Proof 进程秘密摘要,持久化验证旧会话隔离。
ApplicationID core.ID // ApplicationID 服务端认证后的应用归属,用于节点公平派发分组,不接受客户端覆盖。
InstanceID core.ID // InstanceID 已证明秘密的进程标识。
SessionID core.ID // SessionID 当前连接标识。
Epoch uint64 // Epoch 连接代次。
Proof core.Digest // Proof 进程秘密摘要,持久化验证旧会话隔离。
}
// Welcome 给出数据库时钟与控制参数;时间用于 SDK 计算保守的单调时钟期限。