diff --git a/modules/runs/interpreter.go b/modules/runs/interpreter.go index 50a0d7481..ab468517a 100644 --- a/modules/runs/interpreter.go +++ b/modules/runs/interpreter.go @@ -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 {