feat: run nested async workflows (#9119)

This commit is contained in:
Carlos R. L. Rodrigues
2024-09-16 10:06:45 -03:00
committed by GitHub
parent 0bcdcccbe2
commit ef8dc4087e
23 changed files with 295 additions and 100 deletions

View File

@@ -1,7 +1,9 @@
import {
StepResponse,
WorkflowResponse,
createStep,
createWorkflow,
parallelize,
} from "@medusajs/workflows-sdk"
import { setTimeout } from "timers/promises"
@@ -17,9 +19,9 @@ const step_1_background = createStep(
})
)
createWorkflow(
const nestedWorkflow = createWorkflow(
{
name: "workflow_async_background",
name: "nested_sub_flow_async",
},
function (input) {
const resp = step_1_background(input)
@@ -27,3 +29,25 @@ createWorkflow(
return resp
}
)
createWorkflow(
{
name: "workflow_async_background",
},
function (input) {
const [ret] = parallelize(
nestedWorkflow
.runAsStep({
input,
})
.config({ name: "step_sub_flow_1" }),
nestedWorkflow
.runAsStep({
input,
})
.config({ name: "step_sub_flow_2" })
)
return new WorkflowResponse(ret)
}
)