Feat(modules-sdk): Run hooks on application start (#6111)
**What** - run `onApplicationStart` hook when starting modules
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
IModuleService,
|
||||
InternalModuleDeclaration,
|
||||
LinkModuleDefinition,
|
||||
LoadedModule,
|
||||
@@ -85,6 +86,21 @@ export class MedusaModule {
|
||||
return MedusaModule.getModuleInstance(key)
|
||||
})
|
||||
}
|
||||
|
||||
public static onApplicationStart(): void {
|
||||
for (const instances of MedusaModule.instances_.values()) {
|
||||
for (const instance of Object.values(instances) as IModuleService[]) {
|
||||
if (instance?.__hooks) {
|
||||
instance.__hooks?.onApplicationStart
|
||||
?.bind(instance)()
|
||||
.catch(() => {
|
||||
// The module should handle this and log it
|
||||
return void 0
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static clearInstances(): void {
|
||||
MedusaModule.instances_.clear()
|
||||
|
||||
Reference in New Issue
Block a user