MCPcopy Create free account
hub / github.com/astercloud/aster / executeSequential

Method executeSequential

pkg/executionplan/executor.go:127–174  ·  view source on GitHub ↗

executeSequential 顺序执行步骤

(ctx context.Context, plan *ExecutionPlan, toolCtx *tools.ToolContext)

Source from the content-addressed store, hash-verified

125
126// executeSequential 顺序执行步骤
127func (e *Executor) executeSequential(ctx context.Context, plan *ExecutionPlan, toolCtx *tools.ToolContext) error {
128 var firstError error
129
130 for i := range plan.Steps {
131 select {
132 case <-ctx.Done():
133 // 上下文取消,标记剩余步骤为跳过
134 for j := i; j < len(plan.Steps); j++ {
135 plan.Steps[j].Status = StepStatusSkipped
136 }
137 return ctx.Err()
138 default:
139 }
140
141 step := &plan.Steps[i]
142
143 // 跳过已完成的步骤(用于恢复执行)
144 if step.Status == StepStatusCompleted {
145 continue
146 }
147
148 // 检查依赖是否满足
149 if !e.checkDependencies(plan, step) {
150 step.Status = StepStatusSkipped
151 step.Error = "dependencies not satisfied"
152 continue
153 }
154
155 // 执行步骤
156 err := e.executeStep(ctx, plan, step, toolCtx)
157 if err != nil {
158 if firstError == nil {
159 firstError = err
160 }
161
162 // 根据配置决定是否继续
163 if plan.Options != nil && plan.Options.StopOnError {
164 // 标记剩余步骤为跳过
165 for j := i + 1; j < len(plan.Steps); j++ {
166 plan.Steps[j].Status = StepStatusSkipped
167 }
168 return err
169 }
170 }
171 }
172
173 return firstError
174}
175
176// executeParallel 并行执行无依赖的步骤
177func (e *Executor) executeParallel(ctx context.Context, plan *ExecutionPlan, toolCtx *tools.ToolContext) error {

Callers 1

ExecuteMethod · 0.95

Calls 2

checkDependenciesMethod · 0.95
executeStepMethod · 0.95

Tested by

no test coverage detected