chore(medusa-test-utils):Handle errors gracefully (#6901)

**What**
- Better error handling and error message
- update deps management and dynamic import/require
- Pass a new flag to the modules loaders for the module loaders to be able to act depending on it. In that case, the module can determine what should be run or not. e.g in the workflow engine redis, when we are only partially loading the module, we do not want to set the Distributed transaction storage
This commit is contained in:
Adrien de Peretti
2024-04-02 16:10:17 +02:00
committed by GitHub
parent 7895ff3849
commit 82a176e30e
13 changed files with 141 additions and 78 deletions
@@ -7,6 +7,7 @@ export default async ({
container,
logger,
options,
dataLoaderOnly
}: LoaderOptions): Promise<void> => {
const {
url,
@@ -58,6 +59,7 @@ export default async ({
}
container.register({
partialLoading: asValue(true),
redisConnection: asValue(connection),
redisWorkerConnection: asValue(workerConnection),
redisPublisher: asValue(redisPublisher),
@@ -1,10 +1,11 @@
import { asClass } from "awilix"
import { asClass, asValue } from "awilix"
import { RedisDistributedTransactionStorage } from "../utils"
export default async ({ container }): Promise<void> => {
export default async ({ container, dataLoaderOnly }): Promise<void> => {
container.register({
redisDistributedTransactionStorage: asClass(
RedisDistributedTransactionStorage
).singleton(),
dataLoaderOnly: asValue(!!dataLoaderOnly),
})
}
@@ -79,10 +79,12 @@ export class WorkflowOrchestratorService {
protected redisDistributedTransactionStorage_: RedisDistributedTransactionStorage
constructor({
dataLoaderOnly,
redisDistributedTransactionStorage,
redisPublisher,
redisSubscriber,
}: {
dataLoaderOnly: boolean
redisDistributedTransactionStorage: RedisDistributedTransactionStorage
workflowOrchestratorService: WorkflowOrchestratorService
redisPublisher: Redis
@@ -92,7 +94,10 @@ export class WorkflowOrchestratorService {
this.redisSubscriber = redisSubscriber
redisDistributedTransactionStorage.setWorkflowOrchestratorService(this)
DistributedTransaction.setStorage(redisDistributedTransactionStorage)
if (!dataLoaderOnly) {
DistributedTransaction.setStorage(redisDistributedTransactionStorage)
}
this.redisDistributedTransactionStorage_ =
redisDistributedTransactionStorage