From f1c789ec63aa2807c5dd6ccde4bd02a3ca7128bb Mon Sep 17 00:00:00 2001 From: cool Date: Wed, 20 Mar 2024 23:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=9A=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E6=8F=92=E4=BB=B6=E5=A4=9A=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/plugin/event/app.ts | 4 ++-- src/modules/plugin/event/init.ts | 20 ++++++++++++++++++++ src/modules/plugin/service/info.ts | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/modules/plugin/event/init.ts diff --git a/src/modules/plugin/event/app.ts b/src/modules/plugin/event/app.ts index 81e764d..bf8d80c 100644 --- a/src/modules/plugin/event/app.ts +++ b/src/modules/plugin/event/app.ts @@ -12,10 +12,10 @@ import { PLUGIN_CACHE_KEY, PluginCenterService } from '../service/center'; import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager'; /** - * 修改jwt.secret + * 插件事件 */ @CoolEvent() -export class BaseAppEvent { +export class PluginAppEvent { @Logger() coreLogger: ILogger; diff --git a/src/modules/plugin/event/init.ts b/src/modules/plugin/event/init.ts new file mode 100644 index 0000000..884c815 --- /dev/null +++ b/src/modules/plugin/event/init.ts @@ -0,0 +1,20 @@ +import { CoolEvent, Event } from '@cool-midway/core'; +import { Inject } from '@midwayjs/core'; +import { PluginService } from '../service/info'; + +// 插件初始化全局事件 +export const GLOBAL_EVENT_PLUGIN_INIT = 'globalPluginInit'; + +/** + * 接收事件 + */ +@CoolEvent() +export class PluginInitEvent { + @Inject() + pluginService: PluginService; + + @Event(GLOBAL_EVENT_PLUGIN_INIT) + async globalPluginInit() { + await this.pluginService.reInit(); + } +} diff --git a/src/modules/plugin/service/info.ts b/src/modules/plugin/service/info.ts index d402a2c..c80f09e 100644 --- a/src/modules/plugin/service/info.ts +++ b/src/modules/plugin/service/info.ts @@ -1,5 +1,9 @@ import { App, Inject, Provide } from '@midwayjs/decorator'; -import { BaseService, CoolCommException } from '@cool-midway/core'; +import { + BaseService, + CoolCommException, + CoolEventManager, +} from '@cool-midway/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { Equal, Not, Repository } from 'typeorm'; import { PluginInfoEntity } from '../entity/info'; @@ -13,6 +17,7 @@ import * as _ from 'lodash'; import { PluginInfo } from '../interface'; import { PLUGIN_CACHE_KEY, PluginCenterService } from './center'; import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager'; +import { GLOBAL_EVENT_PLUGIN_INIT } from '../event/init'; /** * 插件信息 @@ -37,6 +42,9 @@ export class PluginService extends BaseService { @InjectClient(CachingFactory, 'default') midwayCache: MidwayCache; + @Inject() + coolEventManager: CoolEventManager; + /** * 初始化 * @param data @@ -44,6 +52,8 @@ export class PluginService extends BaseService { */ async modifyAfter() { await this.reInit(); + // 多进程发送全局事件,pm2下生效 + this.coolEventManager.globalEmit(GLOBAL_EVENT_PLUGIN_INIT, false); } /**