fix: ensure that shutdown works in loaderOnly mode (#6893)
This commit is contained in:
1 parent
68aa0971a2
commit
2e914a5fc5
2 files changed
+13
-11
No files matched your search
@@ -62,7 +62,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
|||||||
|
|
||||||
__hooks = {
|
__hooks = {
|
||||||
onApplicationShutdown: async () => {
|
onApplicationShutdown: async () => {
|
||||||
await this.bullWorker_.close(true)
|
await this.bullWorker_?.close(true)
|
||||||
await this.queue_.close()
|
await this.queue_.close()
|
||||||
this.eventBusRedisConnection_.disconnect()
|
this.eventBusRedisConnection_.disconnect()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -119,16 +119,18 @@ export class MedusaModule {
|
|||||||
}
|
}
|
||||||
public static async onApplicationShutdown(): Promise<void> {
|
public static async onApplicationShutdown(): Promise<void> {
|
||||||
await promiseAll(
|
await promiseAll(
|
||||||
[...MedusaModule.instances_.values()].map(instances => {
|
[...MedusaModule.instances_.values()]
|
||||||
return Object.values(instances).map((instance: IModuleService) => {
|
.map((instances) => {
|
||||||
|
return Object.values(instances).map((instance: IModuleService) => {
|
||||||
return instance.__hooks?.onApplicationShutdown
|
return instance.__hooks?.onApplicationShutdown
|
||||||
?.bind(instance)()
|
?.bind(instance)()
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// The module should handle this and log it
|
// The module should handle this and log it
|
||||||
return void 0
|
return void 0
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}).flat()
|
.flat()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,14 +264,13 @@ export class MedusaModule {
|
|||||||
let finishLoading: any
|
let finishLoading: any
|
||||||
let errorLoading: any
|
let errorLoading: any
|
||||||
|
|
||||||
|
const loadingPromise = new Promise((resolve, reject) => {
|
||||||
|
finishLoading = resolve
|
||||||
|
errorLoading = reject
|
||||||
|
})
|
||||||
|
|
||||||
if (!loaderOnly) {
|
if (!loaderOnly) {
|
||||||
MedusaModule.loading_.set(
|
MedusaModule.loading_.set(hashKey, loadingPromise)
|
||||||
hashKey,
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
finishLoading = resolve
|
|
||||||
errorLoading = reject
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let modDeclaration =
|
let modDeclaration =
|
||||||
@@ -330,6 +331,7 @@ export class MedusaModule {
|
|||||||
const services = {}
|
const services = {}
|
||||||
|
|
||||||
if (loaderOnly) {
|
if (loaderOnly) {
|
||||||
|
finishLoading(services)
|
||||||
return services
|
return services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user