feat(taskactions): retry a parked task on the current workflow definition
This commit is contained in:
1 parent
c80d4750a8
commit
9d7287c647
18 files changed
+134
-58
No files matched your search
@@ -79,6 +79,9 @@ type ActionPayload struct {
|
||||
// ResumeFrom is the stage a retry starts at, keeping the results of the
|
||||
// stages before it. Empty runs every stage.
|
||||
ResumeFrom string
|
||||
// CurrentDefinition moves a retry onto the workflow's current stored
|
||||
// definition rather than the version the run is pinned to.
|
||||
CurrentDefinition bool
|
||||
}
|
||||
|
||||
// Actor is who performed an action and the principal whose authority allowed
|
||||
@@ -182,7 +185,9 @@ type Store interface {
|
||||
Requeue(context.Context, int64, string, string) error
|
||||
// RetryTask requeues a parked task, records the operator's worktree mode
|
||||
// for the next dispatch and increments retry_count in one guarded write.
|
||||
RetryTask(context.Context, int64, string, string, string, workflowtask.Resume) error
|
||||
// currentDefinition drops the run's pinned definition so the next dispatch
|
||||
// pins the workflow's current stored version.
|
||||
RetryTask(context.Context, int64, string, string, string, workflowtask.Resume, bool) error
|
||||
// RespondReviewGate is the guarded review gate response write
|
||||
// (internal/domain/storecontract.ReviewGateResponder): it records the
|
||||
// answered document, and for a re-review increments rereview_rounds and
|
||||
@@ -440,7 +445,7 @@ func (s Service) applyRetry(ctx context.Context, task *Task, actor Actor, o outc
|
||||
if !ok {
|
||||
return o, fmt.Errorf("unknown retry mode %q: %w", requested, ErrConflict)
|
||||
}
|
||||
resume, err := resumePoint(task.Stages, payload.ResumeFrom)
|
||||
resume, err := retryStart(task.Stages, payload)
|
||||
if err != nil {
|
||||
return o, fmt.Errorf("%w: %w", err, ErrConflict)
|
||||
}
|
||||
@@ -468,18 +473,27 @@ func (s Service) applyRetry(ctx context.Context, task *Task, actor Actor, o outc
|
||||
}
|
||||
return o, fmt.Errorf("%w: %s", ErrConflict, reason)
|
||||
}
|
||||
err = s.Store.RetryTask(ctx, task.ID, "parked", "", string(mode), resume)
|
||||
err = s.Store.RetryTask(ctx, task.ID, "parked", "", string(mode), resume, payload.CurrentDefinition)
|
||||
if errors.Is(err, storecontract.ErrResumeIncomplete) {
|
||||
err = fmt.Errorf("%q did not complete in its last run, so there is nothing to resume from: %w", resume.After, ErrConflict)
|
||||
}
|
||||
o.event.Kind, o.event.Detail = events.KindTaskRetried, actor.describe("retried")
|
||||
o.event.Data = map[string]any{"retry_count": task.RetryCount + 1, "previous_reason": task.ParkReason, "retry_mode": string(mode)}
|
||||
o.event.Data = map[string]any{"retry_count": task.RetryCount + 1, "previous_reason": task.ParkReason, "retry_mode": string(mode), "current_definition": payload.CurrentDefinition}
|
||||
if resume.From != "" {
|
||||
o.event.Data["resume_from"] = resume.From
|
||||
}
|
||||
return o, err
|
||||
}
|
||||
|
||||
// retryStart resolves where a retry starts. Resume stages name steps of the
|
||||
// pinned definition, which a move to the current definition replaces.
|
||||
func retryStart(stages []string, payload ActionPayload) (workflowtask.Resume, error) {
|
||||
if payload.CurrentDefinition && payload.ResumeFrom != "" {
|
||||
return workflowtask.Resume{}, errors.New("a retry on the current definition runs every step")
|
||||
}
|
||||
return resumePoint(stages, payload.ResumeFrom)
|
||||
}
|
||||
|
||||
// resumePoint resolves a resume stage against the pinned definition's stages.
|
||||
// Stage names are how runs are recorded, so a name two stages share cannot
|
||||
// say which one to resume.
|
||||
|
||||
Reference in new issue
Block a user