mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2024-11-01 22:20:30 +08:00
完善多进程下,插件多进程重新初始化
This commit is contained in:
parent
83f3faed5b
commit
f1c789ec63
@ -12,10 +12,10 @@ import { PLUGIN_CACHE_KEY, PluginCenterService } from '../service/center';
|
|||||||
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改jwt.secret
|
* 插件事件
|
||||||
*/
|
*/
|
||||||
@CoolEvent()
|
@CoolEvent()
|
||||||
export class BaseAppEvent {
|
export class PluginAppEvent {
|
||||||
@Logger()
|
@Logger()
|
||||||
coreLogger: ILogger;
|
coreLogger: ILogger;
|
||||||
|
|
||||||
|
20
src/modules/plugin/event/init.ts
Normal file
20
src/modules/plugin/event/init.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
import { App, Inject, Provide } from '@midwayjs/decorator';
|
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 { InjectEntityModel } from '@midwayjs/typeorm';
|
||||||
import { Equal, Not, Repository } from 'typeorm';
|
import { Equal, Not, Repository } from 'typeorm';
|
||||||
import { PluginInfoEntity } from '../entity/info';
|
import { PluginInfoEntity } from '../entity/info';
|
||||||
@ -13,6 +17,7 @@ import * as _ from 'lodash';
|
|||||||
import { PluginInfo } from '../interface';
|
import { PluginInfo } from '../interface';
|
||||||
import { PLUGIN_CACHE_KEY, PluginCenterService } from './center';
|
import { PLUGIN_CACHE_KEY, PluginCenterService } from './center';
|
||||||
import { CachingFactory, MidwayCache } from '@midwayjs/cache-manager';
|
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')
|
@InjectClient(CachingFactory, 'default')
|
||||||
midwayCache: MidwayCache;
|
midwayCache: MidwayCache;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
coolEventManager: CoolEventManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
* @param data
|
* @param data
|
||||||
@ -44,6 +52,8 @@ export class PluginService extends BaseService {
|
|||||||
*/
|
*/
|
||||||
async modifyAfter() {
|
async modifyAfter() {
|
||||||
await this.reInit();
|
await this.reInit();
|
||||||
|
// 多进程发送全局事件,pm2下生效
|
||||||
|
this.coolEventManager.globalEmit(GLOBAL_EVENT_PLUGIN_INIT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user