电子书地址:https://workflow-engine-book.shuwoom.com
核心表结构
流程表
workflow表
列名 | 类型 | 说明 |
id | int unsigned | id |
name | varchar(200) | 工作流名称 |
user | varchar(100) | 工作流创建人 |
enabled | tinyint(1) | 是否启用 |
desc | varchar(500) | 工作流描述 |
trigger_app | varchar(30) | 工作流中起始触发app类型,如:cron, webhook… |
trigger_token | varchar(50) | trigger token |
start_app_inst_id | varchar(100) | 起始app |
end_app_inst_id | varchar(100) | 起始app |
engine | varchar(100) | 使用的工作流类型,不同的类型执行会有区别,包括:标准工作流和快速工作流,默认使用标准工作流 |
tasks | mediumtext | 工作流中各个节点的配置参数及关系 |
create_at | timestamp | 创建时间 |
update_at | timestamp | 更新时间 |
流程实例表
workflow_inst表
列名 | 类型 | 说明 |
id | int unsigned | 自增长id |
uid | varchar(32) | snowflake算法生成的全局唯一id |
p_uid | varchar(32) | 父uid |
workflow_id | int unsigned | 工作流id |
name | varchar(200) | 工作流名称 |
user | varchar(100) | 工作流创建人 |
executor | varchar(100) | 工作流触发人,默认是工作流创建人 |
status | varchar(10) | 执行状态,请参考流程的生命周期章节 |
trigger_data | mediumtext | 开始事件触发时所传递的数据,例如api的post请求体 |
trigger_app | varchar(30) | 工作流中起始触发app类型,如:cron, webhook… |
start_at | char(19) | 实例开始时间 |
end_at | char(19) | 实例结束时间 |
start_app_inst_id | varchar(100) | 开始执行的app |
end_app_inst_id | varchar(100) | 结束执行的app |
engine | varchar(100) | 使用的引擎,不同的引擎对工作流的执行会有区别,包括:标准引擎和快速引擎,默认使用标准引擎 |
tasks | mediumtext | 工作流中各个节点的配置参数及关系 |
workflow_output | text | 工作流输出结果 |
cost | long int | 执行耗时,单位:毫秒 |
create_at | timestamp | 创建时间 |
update_at | timestamp | 更新时间 |
节点实例表
node_inst表
列名 | 类型 | 说明 |
id | int unsigned | 自增长id |
uid | varchar(32) | snowflake算法生成的全局唯一id |
workflow_uid | varchar(32) | 工作流实例id,引用workflow表的uid字段 |
execution_uid | varchar(32) | 执行uid |
index | int(11) | 索引id,在循环时使用,表示第几次执行 |
node_id | varchar(100) | 前端画布生成的节点id,在每一个流程中是唯一的 |
name | varchar(200) | 原子任务名称 |
desc | varchar(500) | 原子任务说明 |
template | varchar(100) | app模板id类型,如:cron-timer、database-handler |
trigger_token | varchar(50) | trigger token |
trigger_data | mediumtext | trigger data |
task | mediumtext | Task参数数据,不同task参数不一样 |
status | varchar(32) | 状态,请参考节点的生命周期章节 |
execute_ip | varchar(32) | 执行该app的容器ip地址 |
start_at | char(19) | 实例开始时间 |
end_at | char(19) | 实例结束时间 |
cost | long int | 执行耗时,单位:毫秒 |
create_at | timestamp | 创建时间 |
update_at | timestamp | 更新时间 |
核心接口
WFMC定义的所有接口如下:
● 过程定义数据,以及过程定义数据的转换规范
● 支持不同工作流系统间协同工作的接口
● 支持与各种不同IT应用程序交互的接口
● 支持与用户交互的接口
● 提供系统监视,以及标准功能来简化复合工作流应用环境管理的接口
创建流程
请求URL | /api/process |
请求方法 | POST |
说明 | 创建流程 |
请求
各个字段的说明请参考第三章的《流程定义》。
{
"name":"Unknown",
"description":"",
"startTaskInstId":"",
"endTaskInstId":"",
"engine":"fast",
"status":"",
"creator":"admin",
"executor":"",
"timeout":0,
"inputDataSchema":{
...
},
"outputDataSchema":{
...
},
"error":"",
"extension":{
...
},
"metadata":{
...
},
"tasks":[
...
]
}
响应
{
"response": {
"id": "proc-avxhke9u"
}
}
获取流程详情
请求URL | /api/process/{process_id} |
请求方法 | GET |
说明 | 获取特定流程详情 |
请求参数 | – process_id (流程ID,字符串) |
响应 |
请求
-
•
process_id
(流程ID,字符串)
/v1/process/proc-avxhke9u
响应
{
"id":"proc-avxhke9u",
"name":"Unknown",
"description":"",
"startTaskInstId":"",
"endTaskInstId":"",
"engine":"fast",
"status":"",
"creator":"admin",
"executor":"",
"timeout":0,
"inputDataSchema":{
...
},
"outputDataSchema":{
...
},
"error":"",
"extension":{
...
},
"metadata":{
...
},
"tasks":[
...
]
}
获取任务详情
请求URL | /api/process/{process_id}/{task_id} |
请求方法 | GET |
说明 | 获取特定流程下的任务详情 |
请求
-
•
process_id
(流程ID,字符串) -
•
task_id
(任务ID,字符串)
/api/process/proc-10001/task-3udfizra
响应
{
"instId":"task-3udfizra",
"name":"脚本任务执行",
"description":"执行脚本任务",
"template":"script",
"positions":[],
"connections":[],
"parameters":{
"code":{
"label":"代码",
"type":"string",
"value":"",
"default":"",
"required":true
}
},
"errorHandler":{},
"loopHandler":{},
"timeout":0,
"isIgnore":false
}
启动流程实例
请求URL | /api/process/{process_id} |
请求方法 | POST |
说明 | 启动流程实例 |
请求
-
•
process_id
(流程ID,字符串) -
•
payload
(初始化数据,可以为空,也可以传递启动的JSON数据)
/api/process/proc-avxhke9u
{
"param1": "hello world",
"param2": "tester"
}
响应
启动成功后,异步返回流程实例ID
{
"response": {
"id": "1541815603606036480"
}
}
获取流程实例详情
请求URL | /api/processInst/{inst_id} |
请求方法 | GET |
说明 | 获取流程实例详情 |
请求参数 | – inst_id (流程实例ID,字符串) |
响应 |
请求
-
•
inst_id
(流程实例ID,字符串。注意:每个inst_id是唯一的不重复)
/api/processInst/1541815603606036480
响应
这里主要是获取流程实例中各个任务实例在运行时的数据,即runtimes数据。
{
"id":"1541815603606036480",
"proc_id":"proc-avxhke9u",
"name":"Unknown",
"description":"",
"startTaskInstId":"",
"endTaskInstId":"",
"engine":"fast",
"status":"",
"creator":"admin",
"executor":"",
"timeout":0,
"inputDataSchema":{
...
},
"outputDataSchema":{
...
},
"error":"",
"extension":{
...
},
"metadata":{
...
},
"tasks":[
{
"instId":"task-3udfizra",
"name":"脚本任务执行",
"description":"执行脚本任务",
"template":"script",
"positions":[],
"connections":[],
"parameters":{
"code":{
"label":"代码",
"type":"string",
"value":"",
"default":"",
"required":true
}
},
"errorHandler":{},
"loopHandler":{},
"timeout":0,
"isIgnore":false,
"runtimes":[
{
"index":0,
"startAt":1700063265000,
"endAt":1700063307000,
"status":"done",
"error":"",
"input":{
"code":"xxx"
},
"output":"ok"
}
]
}
]
}
获取任务实例详情
请求URL | /api/processInst/{inst_id}/{task_id} |
请求方法 | GET |
说明 | 获取某个流程实例下的某个任务执行详情 |
请求
-
•
inst_id
(流程实例ID,字符串。注意:每个流程实例ID都是唯一不重复的) -
•
task_id
(任务ID,字符串。注意:流程实例中每个任务ID都是唯一不重复的)
/api/processInst/inst-avxhke9u/task-3udfizra
响应
这里只返回对应流程实例中所关注的任务的运行时数据,即runtimes数据。
{
"instId":"task-3udfizra",
"name":"脚本任务执行",
"description":"执行脚本任务",
"template":"script",
"positions":[],
"connections":[],
"parameters":{
"code":{
"label":"代码",
"type":"string",
"value":"",
"default":"",
"required":true
}
},
"errorHandler":{},
"loopHandler":{},
"timeout":0,
"isIgnore":false,
"runtimes":[
{
"index":0,
"startAt":1700063265000,
"endAt":1700063307000,
"status":"done",
"error":"",
"input":{
"code":"xxx"
},
"output":"ok"
}
]
}
查询代办任务
请求URL | /api/taskInsts?user={string}&limit={integer}&offset={integer} |
请求方法 | GET |
说明 | 查询某个用户待处理的任务列表 |
请求
-
•
user
(用户,字符串) -
•
limit
(分页大小,整形) -
•
offset
(分页偏移,整形)
/api/taskInsts?user=zhangsan&limit=20&offset=0
响应
返回的list数组中的任务实例ID:inst-xf2gh3xs9是唯一不重复的。
{
"response":{
"list":[
{
"id":"inst-xf2gh3xs9",
"name":"请假条审批",
"content":"由于.....",
"createAt":"2023-12-01 10:00:00"
}
],
"total":1
}
}
提交任务
请求URL | /api/taskInst/{task_inst_id} |
请求方法 | POST |
说明 | 任务实例提交 |
请求
-
•
task_inst_id
(任务实例ID,字符串) -
•
payload
提交的post参数,根据任务实例的入参来传递key、value数据。可以通过前面的获取任务实例详情接口得到入参列表。
/api/taskInst/inst-xf2gh3xs9
{
"key1": "value1",
"key2": "value2"
}
原文始发于微信公众号(瓶中小人):工作流引擎-核心表结构与接口设计
暂无评论内容