Archived
M5(2/3): process 用例与流转 —— 流程引擎的确定性调度
- routing domain:选边(XOR 恰取一条 + 默认分支兜底;AND 全走)、边映射装配(四类来源 + S-FEEL 转换)、AND 汇合回齐(容忍分支不阻汇合)、审批点驳回走向声明式 - process-service:起单 → 调度节点 → 负责人四策略解析(结果与依据留痕)→ 活动起单 / 审批点卡工位 / 终点收束按来源回执;任务终态到达继续流转或走失败走向四选一; 审批驳回按声明回指定节点重开新实例;状态每次变动后重算聚合投影 - adapter:流程包(id × version)、工作流实例、节点实例三表持久 —— 崩溃后可续跑 ADR 待补项登记为 debt M5-1:§6.1 的 Mastra workflow 编译器作为可替换 adapter 后补, 当前由自持确定性状态机承担,语义等价、usecase 不动 325 个测试通过,门禁五道全绿 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
This commit is contained in:
co-authored by
Claude Opus 5
parent
291fc39179
commit
a8f6eef610
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* process 的 sys schema 表(编码规范 §7 / ADR-002)。
|
||||
* 流程包定义与版本 + 工作流实例 + 节点实例(重开产生新实例,旧实例不再入算)。
|
||||
*/
|
||||
import { boolean, index, integer, jsonb, primaryKey, text, timestamp } from 'drizzle-orm/pg-core';
|
||||
import { sys } from '@shared/db.ts';
|
||||
|
||||
export const processPackageTable = sys.table(
|
||||
'process_package',
|
||||
{
|
||||
id: text('id').notNull(),
|
||||
version: integer('version').notNull(),
|
||||
name: text('name').notNull(),
|
||||
state: text('state').notNull().default('draft'),
|
||||
definition: jsonb('definition').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
publishedAt: timestamp('published_at', { withTimezone: true }),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.id, t.version] }), index('process_package_state_idx').on(t.state)],
|
||||
);
|
||||
|
||||
export const workflowTable = sys.table(
|
||||
'workflow',
|
||||
{
|
||||
id: text('id').primaryKey(),
|
||||
packageId: text('package_id').notNull(),
|
||||
packageVersion: integer('package_version').notNull(),
|
||||
subject: text('subject').notNull(),
|
||||
state: text('state').notNull().default('running'),
|
||||
/** 凡单必有来源 */
|
||||
source: jsonb('source').notNull(),
|
||||
initiation: jsonb('initiation').notNull(),
|
||||
ports: jsonb('ports').notNull().default({}),
|
||||
vars: jsonb('vars').notNull().default({}),
|
||||
startedAt: timestamp('started_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
finishedAt: timestamp('finished_at', { withTimezone: true }),
|
||||
},
|
||||
(t) => [index('workflow_state_idx').on(t.state, t.startedAt)],
|
||||
);
|
||||
|
||||
export const nodeInstanceTable = sys.table(
|
||||
'node_instance',
|
||||
{
|
||||
workflowId: text('workflow_id').notNull(),
|
||||
nodeId: text('node_id').notNull(),
|
||||
instance: integer('instance').notNull(),
|
||||
running: boolean('running').notNull().default(false),
|
||||
waiting: boolean('waiting').notNull().default(false),
|
||||
activated: boolean('activated').notNull().default(true),
|
||||
terminal: text('terminal'),
|
||||
failureDigested: boolean('failure_digested'),
|
||||
taskId: text('task_id'),
|
||||
approvalId: text('approval_id'),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(t) => [
|
||||
primaryKey({ columns: [t.workflowId, t.nodeId, t.instance] }),
|
||||
index('node_instance_task_idx').on(t.taskId),
|
||||
],
|
||||
);
|
||||
Reference in New Issue
Block a user