Workflow Engine Module

In this document, you'll learn what a Workflow Engine Module is and how to use it in your Medusa application.

What is a Workflow Engine Module?#

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.

Default Workflow Engine Module#

Medusa uses the In-Memory Workflow Engine Module by default. For production purposes, it's recommended to use the Redis Workflow Engine Module instead.


How to Use the Workflow Engine Module?#

You can use the registered Workflow Engine Module as part of the 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.

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.

For example:

Code
1import { Modules } from "@medusajs/framework/utils"2import { 3  createStep,4  createWorkflow,5  StepResponse,6  WorkflowResponse,7} from "@medusajs/framework/workflows-sdk"8
9const step1 = createStep(10  "step-1",11  async ({}, { container }) => {12    const workflowEngineService = container.resolve(13      Modules.WORKFLOW_ENGINE14    )15
16    const [workflowExecution] = await workflowEngineService.listWorkflowExecutions({17      transaction_id: transaction_id,18    })19
20    return new StepResponse(workflowExecution)21  } 22)23
24export const workflow = createWorkflow(25  "workflow-1",26  () => {27    const workflowExecution = step1()28
29    return new WorkflowResponse(workflowExecution)30  }31)

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.

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.


List of Workflow Engine Modules#

Medusa provides the following Workflow Engine Modules.

In-Memory
For Development
Redis
For Production
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break