新增插件初始化完成事件

This commit is contained in:
cool 2024-02-21 15:43:40 +08:00
parent ed72f546d4
commit c04a9577af

View File

@ -15,9 +15,12 @@ import { Repository } from 'typeorm';
import { PluginInfo } from '../interface';
import * as _ from 'lodash';
import { CacheManager } from '@midwayjs/cache';
import { CoolEventManager } from '@cool-midway/core';
export const PLUGIN_CACHE_KEY = 'PLUGIN_INIT';
export const EVENT_PLUGIN_READY = 'EVENT_PLUGIN_READY';
/**
*
*/
@ -39,6 +42,9 @@ export class PluginCenterService {
@Inject()
cacheManager: CacheManager;
@Inject()
coolEventManager: CoolEventManager;
@Init()
async init() {
const inits: any[] = (await this.cacheManager.get(PLUGIN_CACHE_KEY)) || [];
@ -48,6 +54,7 @@ export class PluginCenterService {
await this.initHooks();
await this.initPlugin();
await this.cacheManager.set(PLUGIN_CACHE_KEY, inits.concat([process.pid]));
this.coolEventManager.emit(EVENT_PLUGIN_READY);
}
/**