ResumableStep runs a resumable step, skipping the step on a later retry if an earlier attempt already completed it successfully. Step names must be unique across all ResumableStep and ResumableStepCursor calls in the same Worker execution. After a step returns an error, no subsequent steps will be
(ctx context.Context, name string, opts *StepOpts, stepFunc func(ctx context.Context) error)
| 55 | // |
| 56 | // opts may be nil. |
| 57 | func ResumableStep(ctx context.Context, name string, opts *StepOpts, stepFunc func(ctx context.Context) error) { |
| 58 | state := mustResumableState(ctx) |
| 59 | if state.Err != nil { |
| 60 | return |
| 61 | } |
| 62 | if !registerResumableStepName(state, name) { |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | if !state.ResumeMatched { |
| 67 | if name == state.ResumeStep { |
| 68 | state.CompletedStep = name |
| 69 | state.ResumeMatched = true |
| 70 | } |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | previousStepName := state.StepName |
| 75 | state.StepName = name |
| 76 | defer func() { state.StepName = previousStepName }() |
| 77 | |
| 78 | if err := stepFunc(ctx); err != nil { |
| 79 | state.Err = err |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | state.CompletedStep = name |
| 84 | } |
| 85 | |
| 86 | // ResumableStepCursor runs a resumable step that also receives a persisted |
| 87 | // cursor value from an earlier failed attempt, if one was recorded with |
searching dependent graphs…