refactor(runs): run the document's steps in their own function (#2042)

This commit is contained in:
sam committed 2026-11-21 13:54:34 +11:00
1 parent a88f5630fe
commit fb5f3ad472
1 file changed
+30 -20
+30 -20
View File
@@ -160,26 +160,10 @@ func (d Deps) Compile(doc Document) Workflow {
return nil, err
}
}
for i, s := range doc.Steps {
if p.stopped && s.Type != typeNotify {
continue
}
name := s.name(i)
if err := rc.Enter(rc.Context(), name); err != nil {
return nil, err
}
if err := d.runStep(rc, p, s, i); err != nil {
if !stepFailed(err) {
return nil, err
}
// A failed step parks the run for an operator to retry from
// it, unless the step continues on failure.
rc.End(store.StateParked, fmt.Sprintf("step %s: %v", name, err))
return p.encode()
}
if rc.ending != nil {
break
}
if parked, err := d.runSteps(rc, p, doc.Steps); err != nil {
return nil, err
} else if parked {
return p.encode()
}
// An action still held when the document ends is put to people before
// the run finishes, so nothing judgement held runs unapproved or is
@@ -197,6 +181,32 @@ func (d Deps) Compile(doc Document) Workflow {
}
}
// runSteps runs the steps in order until one ends the run. It reports whether
// a step failed and parked the run, for an operator to retry from that step;
// a step that continues on failure does not.
func (d Deps) runSteps(rc *Context, p *progress, steps []Step) (parked bool, err error) {
for i, s := range steps {
if p.stopped && s.Type != typeNotify {
continue
}
name := s.name(i)
if err := rc.Enter(rc.Context(), name); err != nil {
return false, err
}
if err := d.runStep(rc, p, s, i); err != nil {
if !stepFailed(err) {
return false, err
}
rc.End(store.StateParked, fmt.Sprintf("step %s: %v", name, err))
return true, nil
}
if rc.ending != nil {
break
}
}
return false, nil
}
// runStep resolves settings from the run's inputs and earlier results, and
// saves the result under the step ID if the step runs.
func (d Deps) runStep(rc *Context, p *progress, s Step, index int) error {