identity

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package identity 是 Identity 领域模型的原型验证层(见 docs/plans/2026-07-16-Identity领域模型.md),不进正式代码。

Task 结构还没有 BusinessKey/ReplayOf 字段,原型把四概念记在层内的侧车 map 里, 包一层 taskgate 公共 API 跑真调度——验证的是模型语义,不是存储。 侧车用一把互斥锁模拟正式实现里"唯一约束 + 原子校验"的职责 (模型文档问题清单 #6),单进程内语义等价。

约定:走本层 Submit 的任务不要再传 taskgate.WithID(模型终态:ExecutionID 用户不可指定),ID 一律由 broker 生成 ulid。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFinal Replay 目标还没到终态(前置条件①)。
	ErrNotFinal = errors.New("identity: replay target not in final state")
	// ErrInFlight 该 BusinessKey 下还有非终态 execution(前置条件②,"≤1 在途"不变式)。
	ErrInFlight = errors.New("identity: business key has an in-flight execution")
	// ErrAlreadyReplayed 目标已被重放过,链不分叉(前置条件③)。
	ErrAlreadyReplayed = errors.New("identity: execution already replayed (chain must not fork)")
	// ErrCompletedNotAllowed 重放 completed 执行必须显式传 AllowCompleted(评审确认 #2)。
	ErrCompletedNotAllowed = errors.New("identity: replaying a completed execution requires AllowCompleted")
	// ErrUnknownExecution 目标 execution 不存在于本层记录。
	ErrUnknownExecution = errors.New("identity: unknown execution")
	// ErrUnknownKey 该 BusinessKey 不存在。
	ErrUnknownKey = errors.New("identity: unknown business key")
)

模型规则对应的错误。Submit 同键拒绝直接复用 taskgate.ErrTaskExists(契约 2 语义)。

Functions

This section is empty.

Types

type Layer

type Layer struct {
	// contains filtered or unexported fields
}

Layer Identity 原型层。所有侧车状态用一把锁保护, 模拟正式实现里后端原子完成的唯一性校验。

func New

func New(g *taskgate.Gate) *Layer

New 包一个已装配好的 Gate。

func (*Layer) History

func (l *Layer) History(key string) []string

History 返回该 BusinessKey 下的执行历史链(创建顺序)。

func (*Layer) ReplayByID

func (l *Layer) ReplayByID(ctx context.Context, execID string, opt ReplayOptions) (string, error)

ReplayByID 按 ExecutionID 重放。目标必须是其链的链尾(未被重放过)。

func (*Layer) ReplayByKey

func (l *Layer) ReplayByKey(ctx context.Context, key string, opt ReplayOptions) (string, error)

ReplayByKey 按 BusinessKey 重放,天然作用于链尾(最新 execution)。

func (*Layer) ReplayOf

func (l *Layer) ReplayOf(execID string) (string, bool)

ReplayOf 返回该 execution 的重放来源,没有则 ok=false。

func (*Layer) Submit

func (l *Layer) Submit(ctx context.Context, taskType string, payload json.RawMessage, key string, opts ...taskgate.SubmitOption) (string, error)

Submit 带 BusinessKey 的提交。key 为空 = 无业务级幂等,每次都是新 execution; key 非空且键下已存在任何 execution(不论状态)→ 一律拒绝(评审确认 #1)。

type ReplayOptions

type ReplayOptions struct {
	AllowCompleted bool            // 允许重放 completed 的执行,必须显式打开
	Payload        json.RawMessage // nil = 复制旧执行的 Payload(模型问题 #3 的倾向)
}

ReplayOptions Replay 的显式参数。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL