docs: general fixes and overall changes (#7258)

* editing halfway

* edited second half

* adjust starter steps

* fix build

* typo fix
This commit is contained in:
Shahed Nasser
2024-05-07 19:00:28 +03:00
committed by GitHub
parent 8db62827ac
commit 327e446974
57 changed files with 872 additions and 1849 deletions
@@ -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. Its useful to undo or roll back actions youve 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. Its useful to undo or roll back actions youve 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