From 9edadfb01fcdb49af76cbb981da2352b9bbecf1a Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Sun, 5 Apr 2026 12:02:53 +0200 Subject: [PATCH] Add workflow instructions --- starter/AGENTS.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/starter/AGENTS.md b/starter/AGENTS.md index ec36d3d..e7b09f5 100644 --- a/starter/AGENTS.md +++ b/starter/AGENTS.md @@ -309,6 +309,73 @@ edge.To("tags", Tag.Type) // Media has many tags edge.From("media", Media.Type).Ref("tags") // Tag has many media ``` +## Workflows + +### Defining Steps + +- Define a workflow step using `NewStep` and `StepParams`. +- Each step requires a `Name`, `Identifier`, and a `Handler` function. +- The `Handler` function processes the job and returns a result and the next step (if any). + +```go +lastStep := NewStep(&StepParams{ + Name: "Last step", + Identifier: "last_step", + Description: "Last step", + Client: client, + MaxRetries: 3, + Handler: func(ctx context.Context, currentStep *Step, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) { + return queue.GeneralQueueHandlerResult{ + ResultPayload: map[string]interface{}{ + "lastStep": "hello", + }, + }, nil, nil + }, +}) + +firstStep := NewStep(&StepParams{ + Name: "Initial step", + Identifier: "initial_step", + Description: "Initial step", + Client: client, + MaxRetries: 3, + Handler: func(ctx context.Context, currentStep *Step, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) { + return queue.GeneralQueueHandlerResult{ + ResultPayload: map[string]interface{}{ + "firstStep": "hello", + }, + }, lastStep, nil // Return the next step to execute + }, +}) +``` + +### Creating Workflows + +- Define a workflow using `NewWorkflow`, providing a name, identifier, starting step, and all steps in the workflow. + +```go +w := NewWorkflow("Example", "example", firstStep, []*Step{firstStep, lastStep}) +``` + +### Executing Workflows + +- To start a workflow, call the `Execute` method with an initial payload. +- A unique `workflowId` is automatically generated and passed through each step. + +```go +err := workflow.Execute(ctx, map[string]interface{}{ + "input": "start data", +}) +``` + +### Scheduled Workflows + +- Use `NewCronTrigger` to run a workflow at regular intervals. + +```go +NewCronTrigger(ctx, workflow, 1 * time.Hour) +``` + ## Important Instructions Do what has been asked; nothing more, nothing less.