Add methods to retry failed workflows and jobs across all steps and queues
This commit is contained in:
+22
-6
@@ -115,9 +115,9 @@ func (w *Workflow) GenerateId() string {
|
||||
return w.Identifier + "_" + now.Format("20060102150405") + "_" + ersteller.RandomString(5)
|
||||
}
|
||||
|
||||
// Resume restarts a specific workflow execution by its workflowId.
|
||||
// It resets failed and in-progress jobs of all steps back to pending and
|
||||
// starts their queues again if they are running.
|
||||
// Resume restarts a specific workflow execution by its workflowId by
|
||||
// setting any in-progress jobs of all steps back to pending, then starts
|
||||
// their queues again if they are running.
|
||||
func (w *Workflow) Resume(ctx context.Context, workflowId string) error {
|
||||
var allErr error
|
||||
for _, step := range w.AllSteps {
|
||||
@@ -133,9 +133,8 @@ func (w *Workflow) Resume(ctx context.Context, workflowId string) error {
|
||||
}
|
||||
|
||||
// ResumeAll restarts all executions of this workflow across all steps.
|
||||
// For each step it resets any in-progress jobs to pending and failed jobs to
|
||||
// pending with NumberOfTries reset to 0, then starts the queue again if it is
|
||||
// configured as running.
|
||||
// For each step it resets any in-progress jobs to pending, then starts the
|
||||
// queue again if it is configured as running.
|
||||
func (w *Workflow) ResumeAll(ctx context.Context) error {
|
||||
var allErr error
|
||||
for _, step := range w.AllSteps {
|
||||
@@ -150,6 +149,23 @@ func (w *Workflow) ResumeAll(ctx context.Context) error {
|
||||
return allErr
|
||||
}
|
||||
|
||||
// RetryFailed restarts only failed jobs of a specific workflow execution by its
|
||||
// workflowId across all steps by resetting them to pending and their try count
|
||||
// to 0, then starts their queues again if they are running.
|
||||
func (w *Workflow) RetryFailed(ctx context.Context, workflowId string) error {
|
||||
var allErr error
|
||||
for _, step := range w.AllSteps {
|
||||
if step.Queue == nil {
|
||||
// Safety: ensure queues are initialized
|
||||
step.initQueue()
|
||||
}
|
||||
if err := step.Queue.RetryFailedWorkflow(ctx, workflowId); err != nil {
|
||||
allErr = errors.Join(allErr, fmt.Errorf("step %s: %w", step.Name, err))
|
||||
}
|
||||
}
|
||||
return allErr
|
||||
}
|
||||
|
||||
func NewCronTrigger(ctx context.Context, workflow *Workflow, d time.Duration) {
|
||||
go func() {
|
||||
ticker := time.NewTicker(d)
|
||||
|
||||
Reference in New Issue
Block a user