Skip to content

Event 层 ​

Event是NACEB的顶层处理单元。

每个Event由一个Pipeline处理,并以Pipeline的终局结果作为自身结果。

Event的数据由EventInterface描述,运行时由EventInstance承载。

Event的创建方式见构造一个NACEB。

接口 ​

ts
interface EventInterface {
  readonly id: string
  name: string
  pipelineName: string
  payload: unknown
  scope?: string
  blockedBy?: string[]
  parentId?: string
}
字段作用
idEvent的唯一ID
nameEvent名称
pipelineName处理本Event的Pipeline名称
payload交给Pipeline处理的业务数据
scope同一scope的Event不会同时激活
blockedBy前置Event ID;前置Event终局后才会进入队列
parentIdSubEvent所属的父Event ID

DANGER

parentId由SubEvent内建任务设置并追踪,普通任务不应当去填写这个字段。

实例 ​

ts
class EventInstance implements EventInterface {
  status: EventStatus
  final?: unknown

  getPipeline(): PipelineInstance | null
  start(): Promise<void>
  pause(): Promise<boolean>
  resume(): Promise<boolean>
  normalSIG(signal: NormalSignal): Promise<void>
  abort(): Promise<void>
  consume(): unknown
}
成员作用
status当前Event状态
finaldone或failure后的最终结果
getPipeline()获取当前PipelineInstance;尚未激活时返回null
start()使idle状态的Event开始运行
pause()暂停当前Event及其下层实例
resume()恢复已暂停的Event及其下层实例
normalSIG()向PipelineHandler发送普通信号
abort()清理下层实例并使Event进入failure
consume()取出终局结果并移除本EventInstance

通过naceb.getEvent(id)、naceb.listEvent()可以取得EventInstance。

PipelineHandler中也可通过this.event访问当前实例。

WARNING

只有done和failure状态的EventInstance可以消费。消费后,该实例会从NACEB中移除。

调度 ​

EventFSMController负责创建并持有EventInstance队列,同时提供实例查询、终局消费和时钟存活判断。

每一刻到来时,EventFSMController按固定顺序检查队列。

每一刻最多推进一个Event动作:

  1. 对齐运行中的Event与Pipeline:Pipeline终局时收取结果;否则根据当前Task类型,将Event对齐为processing或pending。
  2. 激活一个queue中的Event:同scope没有其他Event占用时,进入activating并创建PipelineInstance。
  3. 解除一个blocked的Event:blockedBy中的Event均已终局或不存在时,进入queue。
  4. 自动消费带有bypassConsume的终局Event。该步骤不占用每刻一个动作的额度。

idle与paused不会由调度器主动推进,分别等待start()与resume()。

start()、pause()、resume()、normalSIG()和abort()由EventInstance直接响应,不等待下一刻。

状态变化见生命周期,NACEB的时钟机制见刻。

Released under the MIT License.