feat(workflow): 增加工作流计费与执行生命周期管理

- 新增计费模块:执行开始建单、终态结算/取消/失败处理,支持按条/按秒/按token计费
- 新增执行生命周期跟踪:优雅关停时取消运行中执行并等待落库
- 新增异步任务等待/通知机制(Wait/Notify)
- 重构执行记录落库与进度上报,统一失败分类与重试语义
- 重命名文件:async_task.go→async.go、flow_checkpoint_store.go→exec_checkpoint.go、flow_graph_util.go→exec_record.go
- 更新 .gitignore 与数据库密码配置
This commit is contained in:
2026-09-03 13:22:22 +08:00
parent 67d049e586
commit d699f7ce14
46 changed files with 2690 additions and 2450 deletions
+10 -1
View File
@@ -9,6 +9,7 @@ import (
// ExecWorkflow 执行工作流
type ExecWorkflow struct {
beans.SQLBaseDO `orm:",inherit"`
UserId int64 `orm:"user_id" json:"userId" description:"执行用户ID(数字,恢复续跑补 X-User-Info 用;creator 是 userName"`
SessionId string `orm:"session_id" json:"sessionId" description:"会话ID"`
FlowId int64 `orm:"flow_id" json:"flowId" description:"工作流ID"`
NodeGroupId string `orm:"node_group_id" json:"nodeGroupId" description:"节点组ID"`
@@ -17,15 +18,18 @@ type ExecWorkflow struct {
Status flow.FlowExecutionStatus `orm:"status" json:"status" description:"状态:1-运行中,2-成功,3-失败"`
TotalTokens int `orm:"total_tokens" json:"totalTokens" description:"总token消耗"`
TotalFee float64 `orm:"total_fee" json:"totalFee" description:"总费用"`
ActualAmount float64 `orm:"actual_amount" json:"actualAmount" description:"业务扣费(用户钱包实际扣除金额,元;结算/取消回填实收,失败/未结算=0,区别于 total_fee=模型按次费用合计)"`
ErrorMessage string `orm:"error_message" json:"errorMessage" description:"错误信息(友好提示)"`
Error string `orm:"error" json:"error" description:"错误明细(原始错误)"`
Retryable int `orm:"retryable" json:"retryable" description:"是否可重试:0-用户取消,1-程序报错"`
Retryable int `orm:"retryable" json:"retryable" description:"是否可重试:0-终局不重试(用户取消/计费门禁拦截),1-可重试(程序报错/关停中断/超时等)"`
RetryCount int `orm:"retry_count" json:"retryCount" description:"已重试次数"`
ChargeOrderId int64 `orm:"charge_order_id" json:"chargeOrderId" description:"关联计费单IDshop-user-trade pricing0=未建单)"`
LastHeartbeat int64 `orm:"last_heartbeat" json:"lastHeartbeat" description:"最后心跳时间(毫秒时间戳)"`
}
type execWorkflowCol struct {
beans.SQLBaseCol
UserId string
SessionId string
FlowId string
NodeGroupId string
@@ -34,15 +38,18 @@ type execWorkflowCol struct {
Status string
TotalTokens string
TotalFee string
ActualAmount string
ErrorMessage string
Error string
Retryable string
RetryCount string
ChargeOrderId string
LastHeartbeat string
}
var ExecWorkflowCol = execWorkflowCol{
SQLBaseCol: beans.DefSQLBaseCol,
UserId: "user_id",
SessionId: "session_id",
FlowId: "flow_id",
NodeGroupId: "node_group_id",
@@ -51,9 +58,11 @@ var ExecWorkflowCol = execWorkflowCol{
Status: "status",
TotalTokens: "total_tokens",
TotalFee: "total_fee",
ActualAmount: "actual_amount",
ErrorMessage: "error_message",
Error: "error",
Retryable: "retryable",
RetryCount: "retry_count",
ChargeOrderId: "charge_order_id",
LastHeartbeat: "last_heartbeat",
}