Add workflow instructions
This commit is contained in:
@@ -309,6 +309,73 @@ edge.To("tags", Tag.Type) // Media has many tags
|
|||||||
edge.From("media", Media.Type).Ref("tags") // Tag has many media
|
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
|
## Important Instructions
|
||||||
|
|
||||||
Do what has been asked; nothing more, nothing less.
|
Do what has been asked; nothing more, nothing less.
|
||||||
|
|||||||
Reference in New Issue
Block a user