docs: general fixes and overall changes (#7258)
* editing halfway * edited second half * adjust starter steps * fix build * typo fix
This commit is contained in:
@@ -10,9 +10,7 @@ In this chapter, you'll learn how to add a compensation function to a step.
|
||||
|
||||
Errors can occur in a workflow. To avoid data inconsistency, define a function to run when an error occurs in a step. This function is called the compensation function.
|
||||
|
||||
Each step can have a compensation function. The compensation function only runs if an error occurs throughout the Workflow. It’s useful to undo or roll back actions you’ve performed in a step.
|
||||
|
||||
For example, change step one to add a compensation function and step two to throw an error:
|
||||
For example:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts" highlights={[["16"], ["17"], ["18"]]}
|
||||
// other imports...
|
||||
@@ -34,7 +32,16 @@ const step1 = createStep(
|
||||
console.log("Oops! Rolling back my changes...")
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
Each step can have a compensation function. The compensation function only runs if an error occurs throughout the Workflow. It’s useful to undo or roll back actions you’ve performed in a step.
|
||||
|
||||
### Test Compensation Function
|
||||
|
||||
1. Add another step that throws an error:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts"
|
||||
// ...
|
||||
const step2 = createStep(
|
||||
"step-2",
|
||||
async () => {
|
||||
@@ -43,9 +50,7 @@ const step2 = createStep(
|
||||
)
|
||||
```
|
||||
|
||||
### Test Compensation Function
|
||||
|
||||
1. Use the steps in a workflow. For example:
|
||||
2. Use the steps in a workflow. For example:
|
||||
|
||||
```ts title="src/workflows/hello-world.ts"
|
||||
import {
|
||||
@@ -74,7 +79,7 @@ const myWorkflow = createWorkflow<
|
||||
export default myWorkflow
|
||||
```
|
||||
|
||||
2. Execute the workflow from a resource, such as an API route:
|
||||
3. Execute the workflow from a resource, such as an API route:
|
||||
|
||||
```ts title="src/api/store/workflow/route.ts"
|
||||
import type {
|
||||
@@ -94,13 +99,13 @@ export async function GET(
|
||||
}
|
||||
```
|
||||
|
||||
3. Run the Medusa application:
|
||||
4. Run the Medusa application:
|
||||
|
||||
```bash npm2yarn
|
||||
npm run dev
|
||||
```
|
||||
|
||||
4. Send a `GET` request to `/store/workflow`:
|
||||
5. Send a `GET` request to `/store/workflow`:
|
||||
|
||||
```bash apiTesting testApiMethod="GET" testApiUrl="http://localhost:9000/store/workflows"
|
||||
curl http://localhost:9000/store/workflow
|
||||
|
||||
Reference in New Issue
Block a user