feat(workflows-sdk,orchestration): async step as background task (#6886)

This commit is contained in:
Carlos R. L. Rodrigues
2024-04-03 11:17:00 +02:00
committed by GitHub
parent 3dcf5224a1
commit a164c0d512
17 changed files with 290 additions and 34 deletions
@@ -5,8 +5,8 @@ import { IWorkflowEngineService } from "@medusajs/workflows-sdk"
import { knex } from "knex"
import { setTimeout } from "timers/promises"
import "../__fixtures__"
import { DB_URL, TestDatabase } from "../utils"
import { workflow2Step2Invoke, workflow2Step3Invoke } from "../__fixtures__"
import { DB_URL, TestDatabase } from "../utils"
const sharedPgConnection = knex<any, any>({
client: "pg",
@@ -172,5 +172,33 @@ describe("Workflow Orchestrator module", function () {
expect(transaction.flow.state).toEqual("reverted")
})
it("should subsctibe to a async workflow and receive the response when it finishes", (done) => {
const transactionId = "trx_123"
const onFinish = jest.fn(() => {
done()
})
void workflowOrcModule.subscribe({
workflowId: "workflow_async_background",
transactionId,
subscriber: (event) => {
if (event.eventType === "onFinish") {
onFinish()
}
},
})
void workflowOrcModule.run("workflow_async_background", {
input: {
myInput: "123",
},
transactionId,
throwOnError: false,
})
expect(onFinish).toHaveBeenCalledTimes(0)
})
})
})