55 lines
3.1 KiB
Go
55 lines
3.1 KiB
Go
package instance
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"time"
|
||
|
||
"git.yuntuo.hk/k2safe/orbit/internal/fault"
|
||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||
"git.yuntuo.hk/k2safe/orbit/platform/auth"
|
||
"git.yuntuo.hk/k2safe/orbit/pulse/service"
|
||
)
|
||
|
||
// EventSummary 只表示已保存的事件,不把当前状态或当前激活反填到历史。
|
||
type EventSummary struct {
|
||
ID core.ID `json:"id"` // ID 原不可变状态事件标识。
|
||
WorkflowID core.ID `json:"workflow_id"` // WorkflowID 已核验授权的流程归属。
|
||
AggregateKind string `json:"aggregate_kind"` // AggregateKind workflow、workflow_step或workflow_signal。
|
||
AggregateID core.ID `json:"aggregate_id"` // AggregateID 产生事件的实例、步骤或信号身份。
|
||
AggregateRevision uint64 `json:"aggregate_revision,string"` // AggregateRevision 来源资源版本,各资源独立,不是全局序号。
|
||
Type string `json:"type"` // Type 原始事件类型,不按当前状态改写。
|
||
StateScope string `json:"state_scope"` // StateScope WORKFLOW、STEP或SIGNAL,说明State记录的是哪类对象。
|
||
State string `json:"state"` // State 该事件保存的状态,不代表对象当前状态。
|
||
StepKey string `json:"step_key,omitempty"` // StepKey 步骤事件的固定定义名称;其他事件省略。
|
||
OccurredAt time.Time `json:"occurred_at"` // OccurredAt 数据库事件记录时间,UTC微秒精度,不是外部业务发生时间或提交水位。
|
||
}
|
||
type EventPage struct {
|
||
WorkflowID core.ID `json:"workflow_id"` // WorkflowID 本页授权的实例身份。
|
||
Revision uint64 `json:"revision,string"` // Revision 本页读取时实例版本,不能作为信号或步骤事件的消费水位。
|
||
Items []EventSummary `json:"items"` // Items 按记录时间和ID倒序的有界摘要,空列表为[]。
|
||
NextCursor string `json:"next_cursor,omitempty"` // NextCursor 绑定实例与事件查询种类,不承诺跨页快照。
|
||
}
|
||
type EventDetail struct {
|
||
EventSummary
|
||
Payload json.RawMessage `json:"payload"` // Payload 原不可变事件元数据,最多64KiB;嵌套数字保留原文本,输入/结果另走资源详情。
|
||
}
|
||
|
||
// ListEvents 要求workflows:audit:read,并核对固定版本全部队列;不能按全局事件ID跨资源读取。
|
||
func (s *Service) ListEvents(ctx context.Context, t auth.Token, id core.ID, in service.HistoryPageInput) (EventPage, error) {
|
||
if id.Validate() != nil {
|
||
return EventPage{}, fault.Invalid("invalid workflow id")
|
||
}
|
||
in, err := historyPage(in)
|
||
if err != nil {
|
||
return EventPage{}, err
|
||
}
|
||
return s.store.ListEvents(ctx, t, id, in)
|
||
}
|
||
func (s *Service) GetEvent(ctx context.Context, t auth.Token, id, event core.ID) (EventDetail, error) {
|
||
if id.Validate() != nil || event.Validate() != nil {
|
||
return EventDetail{}, fault.Invalid("invalid workflow event identity")
|
||
}
|
||
return s.store.GetEvent(ctx, t, id, event)
|
||
}
|