Resume workflow by id
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user