chore(orchestration): idempotent (#7771)
This commit is contained in:
@@ -4,8 +4,18 @@ import {
|
||||
TransactionTimeoutError,
|
||||
WorkflowManager,
|
||||
} from "@medusajs/orchestration"
|
||||
import { IWorkflowEngineService, RemoteQueryFunction } from "@medusajs/types"
|
||||
import { TransactionHandlerType, TransactionStepState } from "@medusajs/utils"
|
||||
import {
|
||||
IWorkflowEngineService,
|
||||
MedusaContainer,
|
||||
RemoteQueryFunction,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
TransactionHandlerType,
|
||||
TransactionStepState,
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { knex } from "knex"
|
||||
import { setTimeout } from "timers/promises"
|
||||
import "../__fixtures__"
|
||||
@@ -28,42 +38,47 @@ const afterEach_ = async () => {
|
||||
}
|
||||
|
||||
describe("Workflow Orchestrator module", function () {
|
||||
describe("Testing basic workflow", function () {
|
||||
let workflowOrcModule: IWorkflowEngineService
|
||||
let query: RemoteQueryFunction
|
||||
let workflowOrcModule: IWorkflowEngineService
|
||||
let query: RemoteQueryFunction
|
||||
let sharedContainer_: MedusaContainer
|
||||
|
||||
afterEach(afterEach_)
|
||||
beforeAll(async () => {
|
||||
const container = createMedusaContainer()
|
||||
container.register(ContainerRegistrationKeys.LOGGER, asValue(console))
|
||||
|
||||
beforeAll(async () => {
|
||||
const {
|
||||
runMigrations,
|
||||
query: remoteQuery,
|
||||
modules,
|
||||
} = await MedusaApp({
|
||||
sharedResourcesConfig: {
|
||||
database: {
|
||||
connection: sharedPgConnection,
|
||||
},
|
||||
const {
|
||||
runMigrations,
|
||||
query: remoteQuery,
|
||||
modules,
|
||||
sharedContainer,
|
||||
} = await MedusaApp({
|
||||
sharedContainer: container,
|
||||
sharedResourcesConfig: {
|
||||
database: {
|
||||
connection: sharedPgConnection,
|
||||
},
|
||||
modulesConfig: {
|
||||
workflows: {
|
||||
resolve: __dirname + "/../..",
|
||||
options: {
|
||||
redis: {
|
||||
url: "localhost:6379",
|
||||
},
|
||||
},
|
||||
modulesConfig: {
|
||||
workflows: {
|
||||
resolve: __dirname + "/../..",
|
||||
options: {
|
||||
redis: {
|
||||
url: "localhost:6379",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
query = remoteQuery
|
||||
|
||||
await runMigrations()
|
||||
|
||||
workflowOrcModule = modules.workflows as unknown as IWorkflowEngineService
|
||||
},
|
||||
})
|
||||
|
||||
query = remoteQuery
|
||||
sharedContainer_ = sharedContainer!
|
||||
|
||||
await runMigrations()
|
||||
|
||||
workflowOrcModule = modules.workflows as unknown as IWorkflowEngineService
|
||||
})
|
||||
|
||||
describe("Testing basic workflow", function () {
|
||||
afterEach(afterEach_)
|
||||
|
||||
it("should return a list of workflow executions and remove after completed when there is no retentionTime set", async () => {
|
||||
@@ -320,10 +335,14 @@ describe("Workflow Orchestrator module", function () {
|
||||
})
|
||||
|
||||
it("should remove scheduled workflow if workflow no longer exists", async () => {
|
||||
const logger = sharedContainer_.resolve<Logger>(
|
||||
ContainerRegistrationKeys.LOGGER
|
||||
)
|
||||
|
||||
const spy = await createScheduled("remove-scheduled", {
|
||||
cron: "* * * * * *",
|
||||
})
|
||||
const logSpy = jest.spyOn(console, "warn")
|
||||
const logSpy = jest.spyOn(logger, "warn")
|
||||
|
||||
await setTimeout(1100)
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -46,7 +46,7 @@ async function deleteKeysByPattern(pattern) {
|
||||
async function cleanRedis() {
|
||||
try {
|
||||
await deleteKeysByPattern("bull:*")
|
||||
await deleteKeysByPattern("dtrans:*")
|
||||
await deleteKeysByPattern("dtrx:*")
|
||||
} catch (error) {
|
||||
console.error("Error:", error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user