fix: 修复工作流执行记录创建与静音模式约束
- 执行记录仅在合法 execId 时写入,查询失败时返回错误 - 字幕构建改为词级精确对齐并增加比例兜底,避免整句被吞 - 静音模式下从转写与段级 prompt 双重杜绝口播/字幕/口型 - 清理静音事件描述中的说话类动词
This commit is contained in:
@@ -147,7 +147,10 @@ func handleExecute(ctx context.Context, conn *wsCommon.WsConnection, payload int
|
||||
_ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "ack", Message: fmt.Sprintf("开始执行工作流(共 %d 个节点)", len(execPayload.FlowContent.Nodes))})
|
||||
|
||||
execId, err := executeOrResume(progressCtx, conn, execPayload)
|
||||
recordWorkflow(saveCtx, execId, time.Since(start), err)
|
||||
if !g.IsEmpty(execId) {
|
||||
glog.Infof(saveCtx, "工作流执行完成,execId: %v", execId)
|
||||
recordWorkflow(saveCtx, execId, time.Since(start), err)
|
||||
}
|
||||
if err != nil {
|
||||
_ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "error", Message: "工作流执行失败", Error: err.Error()})
|
||||
return
|
||||
@@ -243,15 +246,18 @@ func executeOrResume(ctx context.Context, conn *wsCommon.WsConnection, req *sess
|
||||
lastExec, err := sessionDao.ExecWorkflowDao.GetLatestBySessionAndFlow(ctx, conn.SessionId, req.FlowId)
|
||||
if err != nil {
|
||||
glog.Errorf(ctx, "查询最近工作流执行记录失败: %v", err)
|
||||
return execute(ctx, conn, req)
|
||||
return 0, fmt.Errorf("查询最近工作流执行记录失败: %v", err)
|
||||
}
|
||||
if lastExec != nil && *lastExec.Status == *flow.FlowExecutionStatusFailed.Code() && flowContentEqual(lastExec.RequestParams, req.FlowContent) {
|
||||
_ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "round_start", Message: "运行开始", Data: map[string]interface{}{
|
||||
"id": lastExec.Id,
|
||||
}})
|
||||
return reExecute(ctx, lastExec.Id)
|
||||
if lastExec != nil {
|
||||
if *lastExec.Status == *flow.FlowExecutionStatusFailed.Code() && flowContentEqual(lastExec.RequestParams, req.FlowContent) {
|
||||
_ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "round_start", Message: "运行开始", Data: map[string]interface{}{
|
||||
"id": lastExec.Id,
|
||||
}})
|
||||
return reExecute(ctx, lastExec.Id)
|
||||
}
|
||||
return execute(ctx, conn, lastExec.Id, lastExec.Status, req)
|
||||
}
|
||||
return execute(ctx, conn, req)
|
||||
return execute(ctx, conn, 0, nil, req)
|
||||
}
|
||||
|
||||
// flowContentEqual 判断两次工作流参数是否一致(JSON 序列化后字节比对。
|
||||
@@ -269,48 +275,42 @@ func flowContentEqual(a, b *entity.FlowInfo) bool {
|
||||
}
|
||||
|
||||
// execute 执行工作流(首次执行;同会话+同工作流最近一次执行为失败状态时复用该记录重新执行,不新建数据)
|
||||
func execute(ctx context.Context, conn *wsCommon.WsConnection, req *sessionDto.WebSocketExecWorkflowReq) (id int64, err error) {
|
||||
func execute(ctx context.Context, conn *wsCommon.WsConnection, execId int64, status flow.FlowExecutionStatus, req *sessionDto.WebSocketExecWorkflowReq) (id int64, err error) {
|
||||
var nodeGroupId = uuid.NewString()
|
||||
|
||||
// 复用失败记录:查询会话+工作流最近一次执行,若为失败状态则复用同一条记录(更新状态+节点组+本次请求参数),
|
||||
// 全新执行(forceNewRun,参数取本次请求),避免重跑新建数据;查询出错按无记录处理走新建
|
||||
lastExec, qErr := sessionDao.ExecWorkflowDao.GetLatestBySessionAndFlow(ctx, conn.SessionId, req.FlowId)
|
||||
if qErr != nil {
|
||||
glog.Errorf(ctx, "查询最近工作流执行记录失败: %v", qErr)
|
||||
lastExec = nil
|
||||
}
|
||||
if lastExec != nil && *lastExec.Status == *flow.FlowExecutionStatusFailed.Code() {
|
||||
id = lastExec.Id
|
||||
_, err = sessionDao.ExecWorkflowDao.Update(ctx, &sessionDto.UpdateWorkflowReq{
|
||||
Id: id,
|
||||
NodeGroupId: nodeGroupId,
|
||||
Status: flow.FlowExecutionStatusRunning.Code(),
|
||||
RequestParams: req.FlowContent,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
id, err = sessionDao.ExecWorkflowDao.Insert(ctx, &sessionDto.CreateWorkflowReq{
|
||||
if g.IsEmpty(execId) {
|
||||
execId, err = sessionDao.ExecWorkflowDao.Insert(ctx, &sessionDto.CreateWorkflowReq{
|
||||
SessionId: conn.SessionId,
|
||||
FlowId: req.FlowId,
|
||||
NodeGroupId: nodeGroupId,
|
||||
Status: flow.FlowExecutionStatusRunning.Code(),
|
||||
RequestParams: req.FlowContent,
|
||||
})
|
||||
if err != nil {
|
||||
if err != nil || g.IsEmpty(execId) {
|
||||
glog.Errorf(ctx, "工作流执行记录创建失败: %v", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if status == flow.FlowExecutionStatusFailed.Code() {
|
||||
_, err = sessionDao.ExecWorkflowDao.Update(ctx, &sessionDto.UpdateWorkflowReq{
|
||||
Id: execId,
|
||||
NodeGroupId: nodeGroupId,
|
||||
Status: flow.FlowExecutionStatusRunning.Code(),
|
||||
RequestParams: req.FlowContent,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "round_start", Message: "运行开始", Data: map[string]interface{}{
|
||||
"id": id,
|
||||
"id": execId,
|
||||
}})
|
||||
err = BuildExecution(ctx, true, req.FlowId, id, nodeGroupId, conn.SessionId, req.FlowContent)
|
||||
err = BuildExecution(ctx, true, req.FlowId, execId, nodeGroupId, conn.SessionId, req.FlowContent)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return id, nil
|
||||
return execId, nil
|
||||
}
|
||||
|
||||
// reExecute 重新执行工作流
|
||||
|
||||
Reference in New Issue
Block a user