Skip to content

Commit 0a7dc2f

Browse files
authored
feat: cancel successor steps if previous failed (#68)
1 parent 365f3d2 commit 0a7dc2f

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

pkg/dag/node.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ func (n *TargetNode) Status() ExecStatus {
100100
return ExecStatusSuccess
101101
}
102102

103+
// StatusAnyFailed determines if any runner in the target has failed.
104+
func (n *TargetNode) StatusAnyFailed() bool {
105+
for _, r := range n.Execution.Runners {
106+
if r.Status == ExecStatusFailed {
107+
return true
108+
}
109+
}
110+
111+
return false
112+
}
113+
103114
// PropagateExecStatus propagates the execution status forward.
104115
func (n *TargetNode) PropagateExecStatus() {
105116
for _, f := range n.Forward {

pkg/dag/run-concurrent.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,24 @@ func addRunnerTasks(
161161
runner.RunnerID,
162162
}
163163

164+
// Always on finish propagate exec status.
165+
defer func() { node.PropagateExecStatus() }()
166+
164167
if node.Execution.Cancel {
165168
log.Debugf(
166169
"Runner '%v' for target '%v' is cancelled by dependency.",
167170
runnerIdx,
168171
node.Target.ID,
169172
)
170173

171-
node.PropagateExecStatus()
174+
return
175+
} else if node.StatusAnyFailed() {
176+
log.Debugf(
177+
"Target '%v' is failed already. Skip runner '%v', step: '%v'.",
178+
node.Target.ID,
179+
runner.RunnerID,
180+
stepIdx,
181+
)
172182

173183
return
174184
}
@@ -191,8 +201,6 @@ func addRunnerTasks(
191201
} else {
192202
status.Status = ExecStatusSuccess
193203
}
194-
195-
node.PropagateExecStatus()
196204
}()
197205

198206
err = ExecuteRunner(

pkg/dag/run.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,21 @@ func executeRunners(
178178
rD.inst.RunnerID,
179179
}
180180

181-
if rD.node.Execution.Cancel {
181+
switch {
182+
case rD.node.Execution.Cancel:
182183
log.Debugf(
183184
"Target '%v' is cancelled by prev. target. Skip runner '%v'",
185+
rD.node.Target.ID,
184186
rD.inst.RunnerID,
187+
)
188+
case rD.node.StatusAnyFailed():
189+
log.Debugf(
190+
"Target '%v' is failed already. Skip runner '%v', step: '%v'.",
185191
rD.node.Target.ID,
192+
rD.inst.RunnerID,
193+
rD.step.Index,
186194
)
187-
} else {
195+
default:
188196
log.Info("Starting runner.", "runner", rD.inst.RunnerID, "target", rD.targetID)
189197

190198
e := ExecuteRunner(

0 commit comments

Comments
 (0)