|
1
|
import { CardList } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `Workflow Engine Module`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
In this document, you'll learn what a Workflow Engine Module is and how to use it in your Medusa application. |
|
10
|
|
|
11
|
## What is a Workflow Engine Module? |
|
12
|
|
|
13
|
A Workflow Engine Module handles tracking and recording the transactions and statuses of workflows and their steps. It can use custom mechanism or integrate a third-party service. |
|
14
|
|
|
15
|
### Default Workflow Engine Module |
|
16
|
|
|
17
|
Medusa uses the [In-Memory Workflow Engine Module](./in-memory/page.mdx) by default. For production purposes, it's recommended to use the [Redis Workflow Engine Module](./redis/page.mdx) instead. |
|
18
|
|
|
19
|
--- |
|
20
|
|
|
21
|
## How to Use the Workflow Engine Module? |
|
22
|
|
|
23
|
You can use the registered Workflow Engine Module as part of the [workflows](!docs!/learn/fundamentals/workflows) you build for your custom features. A workflow is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism. |
|
24
|
|
|
25
|
In a step of your workflow, you can resolve the Workflow Engine Module's service and use its methods to track and record the transactions and statuses of workflows and their steps. |
|
26
|
|
|
27
|
For example: |
|
28
|
|
|
29
|
```ts |
|
30
|
import { Modules } from "@medusajs/framework/utils" |
|
31
|
import { |
|
32
|
createStep, |
|
33
|
createWorkflow, |
|
34
|
StepResponse, |
|
35
|
WorkflowResponse, |
|
36
|
} from "@medusajs/framework/workflows-sdk" |
|
37
|
|
|
38
|
const step1 = createStep( |
|
39
|
"step-1", |
|
40
|
async ({}, { container }) => { |
|
41
|
const workflowEngineService = container.resolve( |
|
42
|
Modules.WORKFLOW_ENGINE |
|
43
|
) |
|
44
|
|
|
45
|
const [workflowExecution] = await workflowEngineService.listWorkflowExecutions({ |
|
46
|
transaction_id: transaction_id, |
|
47
|
}) |
|
48
|
|
|
49
|
return new StepResponse(workflowExecution) |
|
50
|
} |
|
51
|
) |
|
52
|
|
|
53
|
export const workflow = createWorkflow( |
|
54
|
"workflow-1", |
|
55
|
() => { |
|
56
|
const workflowExecution = step1() |
|
57
|
|
|
58
|
return new WorkflowResponse(workflowExecution) |
|
59
|
} |
|
60
|
) |
|
61
|
``` |
|
62
|
|
|
63
|
In the example above, you create a workflow that has a step. In the step, you resolve the service of the Workflow Engine Module from the [Medusa container](!docs!/learn/fundamentals/medusa-container). |
|
64
|
|
|
65
|
Then, you use the `listWorkflowExecutions` method of the Workflow Engine Module to list the workflow executions with the transaction ID `transaction_id`. The workflow execution is then returned as a response from the step and the workflow. |
|
66
|
|
|
67
|
--- |
|
68
|
|
|
69
|
## List of Workflow Engine Modules |
|
70
|
|
|
71
|
Medusa provides the following Workflow Engine Modules. |
|
72
|
|
|
73
|
<CardList |
|
74
|
items={[ |
|
75
|
{ |
|
76
|
title: "In-Memory", |
|
77
|
href: "/infrastructure-modules/workflow-engine/in-memory", |
|
78
|
badge: { |
|
79
|
variant: "neutral", |
|
80
|
children: "For Development" |
|
81
|
} |
|
82
|
}, |
|
83
|
{ |
|
84
|
title: "Redis", |
|
85
|
href: "/infrastructure-modules/workflow-engine/redis", |
|
86
|
badge: { |
|
87
|
variant: "green", |
|
88
|
children: "For Production" |
|
89
|
} |
|
90
|
} |
|
91
|
]} |
|
92
|
/> |