Resume workflow by id

This commit is contained in:
Achim Rohn
2026-04-08 15:38:07 +02:00
parent a383129abb
commit 12d22efc74
2 changed files with 74 additions and 0 deletions
+18
View File
@@ -2,6 +2,7 @@ package workflow
import (
"context"
"errors"
"fmt"
"time"
@@ -114,6 +115,23 @@ 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.
func (w *Workflow) Resume(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.ResumeWorkflow(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)