refactor(runs): run the document's steps in their own function (#2042)
This commit is contained in:
1 file changed
+30
-20
+30
-20
@@ -160,26 +160,10 @@ func (d Deps) Compile(doc Document) Workflow {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, s := range doc.Steps {
|
if parked, err := d.runSteps(rc, p, doc.Steps); err != nil {
|
||||||
if p.stopped && s.Type != typeNotify {
|
return nil, err
|
||||||
continue
|
} else if parked {
|
||||||
}
|
return p.encode()
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// An action still held when the document ends is put to people before
|
// An action still held when the document ends is put to people before
|
||||||
// the run finishes, so nothing judgement held runs unapproved or is
|
// 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
|
// runStep resolves settings from the run's inputs and earlier results, and
|
||||||
// saves the result under the step ID if the step runs.
|
// saves the result under the step ID if the step runs.
|
||||||
func (d Deps) runStep(rc *Context, p *progress, s Step, index int) error {
|
func (d Deps) runStep(rc *Context, p *progress, s Step, index int) error {
|
||||||
|
|||||||
Reference in new issue
Block a user