Properly add ids for workflow execution and add first visualization

This commit is contained in:
Achim Rohn
2026-04-04 11:31:18 +02:00
parent b5c410c419
commit 6312033fad
5 changed files with 227 additions and 20 deletions
+15 -5
View File
@@ -48,7 +48,8 @@ func (s *Step) AddNextStep(step *Step) {
const workflowIdParam = "workflowId"
func (s *Step) Execute(ctx context.Context, payload map[string]interface{}) error {
func (s *Step) Execute(ctx context.Context, payload map[string]any) error {
ersteller.Debug("Executing step '%s'", s.Name, "payload", payload)
_, err := s.Queue.Enqueue(ctx, payload, s.MaxRetries, -1, queue.WithWorkflowId(payload[workflowIdParam].(string)))
if err != nil {
return err
@@ -58,11 +59,14 @@ func (s *Step) Execute(ctx context.Context, payload map[string]interface{}) erro
}
func (s *Step) HandleQueue(ctx context.Context, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, error) {
workflowId := job.Payload[workflowIdParam].(string)
result, nextStep, err := s.Handler(ctx, s, job)
if err != nil {
return result, err
}
if nextStep != nil {
result.ResultPayload[workflowIdParam] = workflowId
ersteller.Debug("Moving to next step ", nextStep.Name, "payload", result.ResultPayload)
err = nextStep.Execute(ctx, result.ResultPayload)
if err != nil {
failurePayload := result.FailurePayload
@@ -80,18 +84,24 @@ type Workflow struct {
Name string
Identifier string
FirstStep *Step
AllSteps []*Step
}
func NewWorkflow(name string, identifier string, firstStep *Step) *Workflow {
go func() {}()
func NewWorkflow(name string, identifier string, firstStep *Step, allSteps []*Step) *Workflow {
return &Workflow{
Name: name,
FirstStep: firstStep,
Identifier: identifier,
AllSteps: allSteps,
}
}
func (w *Workflow) generateId() string {
func (w *Workflow) Execute(ctx context.Context, payload map[string]any) error {
payload[workflowIdParam] = w.GenerateId()
return w.FirstStep.Execute(ctx, payload)
}
func (w *Workflow) GenerateId() string {
now := time.Now()
return w.Identifier + "_" + now.Format("20060102150405")
}
@@ -107,7 +117,7 @@ func NewCronTrigger(ctx context.Context, workflow *Workflow, d time.Duration) {
return
case <-ticker.C:
err := workflow.FirstStep.Execute(ctx, map[string]interface{}{
"workflowId": workflow.generateId(),
"workflowId": workflow.GenerateId(),
})
if err != nil {
ersteller.Error("Failed to execute cron trigger for workflow '", workflow.Name, "': ", err.Error())