feat: Ensure async workflow executions have access to shared container (#8157)

* feat: Ensure async workflow executions have access to shared container

* fix: Register workflow worker on application start
This commit is contained in:
Stevche Radevski
2024-07-17 12:17:48 +02:00
committed by GitHub
parent 1acfdc4ffe
commit 26d600b6db
15 changed files with 140 additions and 38 deletions

View File

@@ -6,8 +6,10 @@ import {
} from "@medusajs/workflows-sdk"
export const createScheduled = (name: string, schedule?: SchedulerOptions) => {
const workflowScheduledStepInvoke = jest.fn((input, context) => {
return new StepResponse({})
const workflowScheduledStepInvoke = jest.fn((input, { container }) => {
return new StepResponse({
testValue: container.resolve("test-value"),
})
})
const step = createStep("step_1", workflowScheduledStepInvoke)

View File

@@ -21,6 +21,7 @@ import {
} from "../__fixtures__/workflow_event_group_id"
import { createScheduled } from "../__fixtures__/workflow_scheduled"
import { WorkflowsModuleService } from "@services"
import { asFunction } from "awilix"
jest.setTimeout(100000)
@@ -367,6 +368,25 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
)
})
it("the scheduled workflow should have access to the shared container", async () => {
const sharedContainer =
workflowOrcModule["workflowOrchestratorService_"]["container_"]
sharedContainer.register(
"test-value",
asFunction(() => "test")
)
const spy = await createScheduled("remove-scheduled", {
cron: "* * * * * *",
})
await jest.runOnlyPendingTimersAsync()
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveReturnedWith(
expect.objectContaining({ output: { testValue: "test" } })
)
})
it("should fetch an idempotent workflow after its completion", async () => {
const { transaction: firstRun } = await workflowOrcModule.run(
"workflow_idempotent",