fix(workflows-sdk): name for when/then step (#10459)
This commit is contained in:
committed by
GitHub
parent
7ff3f15d6d
commit
90ae187e09
@@ -3,3 +3,4 @@ export * from "./workflow_2"
|
||||
export * from "./workflow_async"
|
||||
export * from "./workflow_step_timeout"
|
||||
export * from "./workflow_transaction_timeout"
|
||||
export * from "./workflow_when"
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
StepResponse,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { setTimeout } from "timers/promises"
|
||||
|
||||
const step_1_background = createStep(
|
||||
{
|
||||
@@ -13,8 +12,6 @@ const step_1_background = createStep(
|
||||
async: true,
|
||||
},
|
||||
jest.fn(async (input) => {
|
||||
await setTimeout(Math.random() * 300)
|
||||
|
||||
return new StepResponse(input)
|
||||
})
|
||||
)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
createStep,
|
||||
createWorkflow,
|
||||
StepResponse,
|
||||
when,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
const step1 = createStep(
|
||||
{
|
||||
name: "step1",
|
||||
async: true,
|
||||
},
|
||||
async (_, context) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000))
|
||||
return new StepResponse({ result: "step1" })
|
||||
}
|
||||
)
|
||||
const step2 = createStep("step2", async (input: string, context) => {
|
||||
return new StepResponse({ result: input })
|
||||
})
|
||||
const step3 = createStep(
|
||||
"step3",
|
||||
async (input: string | undefined, context) => {
|
||||
return new StepResponse({ result: input ?? "default response" })
|
||||
}
|
||||
)
|
||||
|
||||
const subWorkflow = createWorkflow(
|
||||
"wf-when-sub",
|
||||
function (input: WorkflowData<string>) {
|
||||
return new WorkflowResponse(step2(input))
|
||||
}
|
||||
)
|
||||
|
||||
createWorkflow("wf-when", function (input: { callSubFlow: boolean }) {
|
||||
step1()
|
||||
const subWorkflowRes = when("sub-flow", { input }, ({ input }) => {
|
||||
return input.callSubFlow
|
||||
}).then(() => {
|
||||
const res = subWorkflow.runAsStep({
|
||||
input: "hi from outside",
|
||||
})
|
||||
|
||||
return {
|
||||
result: res,
|
||||
}
|
||||
}) as any
|
||||
|
||||
return new WorkflowResponse(step3(subWorkflowRes.result))
|
||||
})
|
||||
Reference in New Issue
Block a user