package flow import ( "context" wsCommon "gitea.redpowerfuture.com/red-future/common/websocket" ) // ====================== 进度上报 ====================== type wsProgressCtxKey struct{} // ProgressReporter 节点执行进度回调接口 type ProgressReporter interface { ReportStart(nodeId, nodeName string, nodeIndex, nodeCount int) ReportComplete(nodeId, nodeName string, nodeIndex, nodeCount int) } // GetProgressReporter 从context中获取进度上报器 func GetProgressReporter(ctx context.Context) ProgressReporter { if reporter, ok := ctx.Value(wsProgressCtxKey{}).(ProgressReporter); ok { return reporter } return nil } // 进度上报由 exec_hub.go 的 execHub 实现(单执行事件中枢,可多连接订阅);wsProgressCtxKey/ProgressReporter/GetProgressReporter 保留。 // handleCancel 取消工作流执行 func handleCancel(ctx context.Context, conn *wsCommon.WsConnection, _ interface{}) { if cancel := getExecCancel(conn); cancel != nil { cancel() } _ = writeJSON(conn, &wsCommon.WsPushMsg{Type: "ack", Message: "已取消工作流执行"}) } // ====================== 工具函数 ====================== func getExecCancel(conn *wsCommon.WsConnection) context.CancelFunc { cancel, _ := wsCommon.GetMetaT[context.CancelFunc](conn, "execCancel") return cancel } // writeJSON 业务层写入,委托 WsConnection.WriteJSON(共享 writeMu 写锁) func writeJSON(conn *wsCommon.WsConnection, data interface{}) error { return conn.WriteJSON(data) }