Execute 执行工作流
(ctx context.Context, workflowID string, inputs map[string]any)
| 187 | |
| 188 | // Execute 执行工作流 |
| 189 | func (e *Engine) Execute(ctx context.Context, workflowID string, inputs map[string]any) (*WorkflowResult, error) { |
| 190 | // 加载工作流定义 |
| 191 | def, err := e.loadWorkflowDefinition(workflowID) |
| 192 | if err != nil { |
| 193 | return nil, fmt.Errorf("failed to load workflow definition: %w", err) |
| 194 | } |
| 195 | |
| 196 | // 验证输入 |
| 197 | if err := e.validateInputs(def, inputs); err != nil { |
| 198 | return nil, fmt.Errorf("invalid inputs: %w", err) |
| 199 | } |
| 200 | |
| 201 | // 创建执行实例 |
| 202 | execution, err := e.createExecution(def, inputs) |
| 203 | if err != nil { |
| 204 | return nil, fmt.Errorf("failed to create execution: %w", err) |
| 205 | } |
| 206 | |
| 207 | // 启动执行 |
| 208 | go e.executeWorkflow(execution) |
| 209 | |
| 210 | // 等待完成 |
| 211 | select { |
| 212 | case <-execution.done: |
| 213 | return execution.buildResult(), nil |
| 214 | case <-ctx.Done(): |
| 215 | e.cancelExecution(execution.ID) |
| 216 | return nil, ctx.Err() |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // ExecuteAsync 异步执行工作流 |
| 221 | func (e *Engine) ExecuteAsync(ctx context.Context, workflowID string, inputs map[string]any) (string, error) { |
nothing calls this directly
no test coverage detected