完善多进程下,插件多进程重新初始化

This commit is contained in:
cool 2024-03-20 23:16:08 +08:00
parent 83f3faed5b
commit f1c789ec63
3 changed files with 33 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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);
}
/**