feat(workflows-sdk,orchestration): async step as background task (#6886)
This commit is contained in:
1 parent
3dcf5224a1
commit
a164c0d512
17 files changed
+290
-34
No files matched your search
@@ -1,4 +1,5 @@
|
||||
export * from "./workflow_1"
|
||||
export * from "./workflow_2"
|
||||
export * from "./workflow_async"
|
||||
export * from "./workflow_step_timeout"
|
||||
export * from "./workflow_transaction_timeout"
|
||||
@@ -25,8 +25,6 @@ const step_1 = createStep(
|
||||
const step_2 = createStep(
|
||||
"step_2",
|
||||
jest.fn((input, context) => {
|
||||
console.log("triggered async request", context.metadata.idempotency_key)
|
||||
|
||||
if (input) {
|
||||
return new StepResponse({ notAsyncResponse: input.hey })
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ const step_1 = createStep(
|
||||
const step_2 = createStep(
|
||||
"step_2",
|
||||
jest.fn((input, context) => {
|
||||
console.log("triggered async request", context.metadata.idempotency_key)
|
||||
|
||||
if (input) {
|
||||
return new StepResponse({ notAsyncResponse: input.hey })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
StepResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { setTimeout } from "timers/promises"
|
||||
|
||||
const step_1_background = createStep(
|
||||
{
|
||||
name: "step_1_background",
|
||||
async: true,
|
||||
},
|
||||
jest.fn(async (input) => {
|
||||
await setTimeout(200)
|
||||
|
||||
return new StepResponse(input)
|
||||
})
|
||||
)
|
||||
|
||||
createWorkflow(
|
||||
{
|
||||
name: "workflow_async_background",
|
||||
},
|
||||
function (input) {
|
||||
const resp = step_1_background(input)
|
||||
|
||||
return resp
|
||||
}
|
||||
)
|
||||
+1
-1
@@ -22,7 +22,7 @@ const step_1_async = createStep(
|
||||
},
|
||||
|
||||
jest.fn(async (input) => {
|
||||
return new StepResponse(input, { compensate: 123 })
|
||||
return
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user