diff --git a/packages/event-bus-redis/src/services/event-bus-redis.ts b/packages/event-bus-redis/src/services/event-bus-redis.ts index 270349dfb1..628ada4933 100644 --- a/packages/event-bus-redis/src/services/event-bus-redis.ts +++ b/packages/event-bus-redis/src/services/event-bus-redis.ts @@ -62,7 +62,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService __hooks = { onApplicationShutdown: async () => { - await this.bullWorker_.close(true) + await this.bullWorker_?.close(true) await this.queue_.close() this.eventBusRedisConnection_.disconnect() }, diff --git a/packages/modules-sdk/src/medusa-module.ts b/packages/modules-sdk/src/medusa-module.ts index 59237a65f9..0ed04f887e 100644 --- a/packages/modules-sdk/src/medusa-module.ts +++ b/packages/modules-sdk/src/medusa-module.ts @@ -119,16 +119,18 @@ export class MedusaModule { } public static async onApplicationShutdown(): Promise { await promiseAll( - [...MedusaModule.instances_.values()].map(instances => { - return Object.values(instances).map((instance: IModuleService) => { + [...MedusaModule.instances_.values()] + .map((instances) => { + return Object.values(instances).map((instance: IModuleService) => { return instance.__hooks?.onApplicationShutdown ?.bind(instance)() .catch(() => { // The module should handle this and log it return void 0 }) + }) }) - }).flat() + .flat() ) } @@ -262,14 +264,13 @@ export class MedusaModule { let finishLoading: any let errorLoading: any + const loadingPromise = new Promise((resolve, reject) => { + finishLoading = resolve + errorLoading = reject + }) + if (!loaderOnly) { - MedusaModule.loading_.set( - hashKey, - new Promise((resolve, reject) => { - finishLoading = resolve - errorLoading = reject - }) - ) + MedusaModule.loading_.set(hashKey, loadingPromise) } let modDeclaration = @@ -330,6 +331,7 @@ export class MedusaModule { const services = {} if (loaderOnly) { + finishLoading(services) return services }