feat: add durable result journal and subscription delivery core
This commit is contained in:
@@ -27,6 +27,10 @@ type Delivery struct {
|
||||
LeaseUntil *time.Time `db:"lease_until"`
|
||||
// Attempts 已产生的交付尝试次数,不等同于业务执行次数。
|
||||
Attempts uint32 `db:"attempts"`
|
||||
// AttemptBudget 累计允许发送次数;人工追加预算,不重置Attempts或LeaseEpoch。
|
||||
AttemptBudget uint32 `db:"attempt_budget"`
|
||||
// TokenDigest 最近交付秘密的摘要;首次发送前为空,确认后保留以验证重复确认。
|
||||
TokenDigest *core.Digest `db:"token_digest"`
|
||||
// AcknowledgedAt 接收方可靠处理后的确认时间;未确认时为空。
|
||||
AcknowledgedAt *time.Time `db:"acknowledged_at"`
|
||||
}
|
||||
|
||||
38
platform/model/event_stream.go
Normal file
38
platform/model/event_stream.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
// EventStream 表示命名空间结果流;独立锁行避免升级认证身份共享锁。
|
||||
// 对应 orbit_event_streams;序号分配必须与任务状态和结果日志同事务提交。
|
||||
type EventStream struct {
|
||||
// NamespaceID 结果流所属命名空间,也是序号分配锁的主键。
|
||||
NamespaceID core.ID `db:"namespace_id"`
|
||||
// LastSequence 已分配序号,从1开始;回滚不消耗序号,0表示尚无结果。
|
||||
LastSequence uint64 `db:"last_sequence"`
|
||||
// RetainedFromSequence 最早保留序号;首版不清理,固定为1,防止以后静默跨过缺失历史。
|
||||
RetainedFromSequence uint64 `db:"retained_from_sequence"`
|
||||
// CreatedAt 结果流创建时间,统一UTC,精度微秒。
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
// UpdatedAt 最后分配序号时间,不能代替结果序号。
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
func (EventStream) TableName() string { return "orbit_event_streams" }
|
||||
|
||||
// ResultEvent 表示从迁移13启用的不可变任务结果快照;不补造历史任务事件。
|
||||
// 对应 orbit_result_events;Record.ID 与来源 Event.ID 相同,关联由事务校验。
|
||||
type ResultEvent struct {
|
||||
// Record 包含所属命名空间、来源事件标识、固定版本1及UTC时间。
|
||||
core.Record
|
||||
// Sequence 命名空间内提交有序的结果序号,首个为1。
|
||||
Sequence uint64 `db:"sequence"`
|
||||
// QueueID 来源任务队列,订阅必须具备该队列的消费权限。
|
||||
QueueID core.ID `db:"queue_id"`
|
||||
// Snapshot 版本化结果快照JSON,保留数值精度,不包含任务输入或租约秘密。
|
||||
Snapshot core.JSON `db:"snapshot"`
|
||||
}
|
||||
|
||||
func (ResultEvent) TableName() string { return "orbit_result_events" }
|
||||
@@ -13,10 +13,20 @@ type Subscription struct {
|
||||
Name string `db:"name"`
|
||||
// CredentialID 关联的命名空间凭据标识。
|
||||
CredentialID core.ID `db:"credential_id"`
|
||||
// Filter 订阅过滤规则的 JSON 文档。
|
||||
// Filter 冻结的结果事件类型数组JSON;创建后不能改写,以免静默漏消费。
|
||||
Filter core.JSON `db:"filter"`
|
||||
// Enabled 是否启用;关闭后拒绝相应的新接入或新操作。
|
||||
// Enabled 是否启用新交付;暂停不撤销已发出的结果,也不拒绝有效确认。
|
||||
Enabled bool `db:"enabled"`
|
||||
// QueueID 创建时冻结的队列;历史占位记录为空且不允许消费。
|
||||
QueueID *core.ID `db:"queue_id"`
|
||||
// CursorSequence 已扫描并物化交付的结果序号,不表示消费者已确认。
|
||||
CursorSequence uint64 `db:"cursor_sequence"`
|
||||
// PendingCount 未确认交付数,包含次数耗尽记录;每次有效确认只减一次。
|
||||
PendingCount uint32 `db:"pending_count"`
|
||||
// MaxPending 未确认交付上限,1至1000;达到后保留来源日志并暂停物化。
|
||||
MaxPending uint32 `db:"max_pending"`
|
||||
// MaxAttempts 新交付的初始发送次数上限,1至100,不等同于任务执行次数。
|
||||
MaxAttempts uint32 `db:"max_attempts"`
|
||||
}
|
||||
|
||||
func (Subscription) TableName() string { return "orbit_subscriptions" }
|
||||
|
||||
Reference in New Issue
Block a user