fix: ensure that shutdown works in loaderOnly mode (#6893)
This commit is contained in:
@@ -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()
|
||||
},
|
||||
|
||||
@@ -119,16 +119,18 @@ export class MedusaModule {
|
||||
}
|
||||
public static async onApplicationShutdown(): Promise<void> {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user