feat(center): 新增通知实时推送 WS /ws/notifications,管理台建单秒达
挂到 Koa 同一 http.Server 的 upgrade 事件(复用 8800,不占新端口、不改 nginx),X-API-Token 握手鉴权,帧格式对齐执行机 notifier.js;新建通知后立即广播(target=all / account),GET /api/notifications 轮询继续兜底。 连接状态放模块作用域(生命周期挂载与请求内推送的 provider 实例不保证同一个),心跳 30s 清理半开连接;src/index.ts 补导出(bundle 关闭 moduleDetector 时必须显式导出)。 部署 SOP 增加 WS 端点探针,客户端交接文档补 /ws/notifications 契约。
This commit is contained in:
@@ -22,6 +22,7 @@ import * as upload from '@midwayjs/upload';
|
||||
// import * as rpc from '@cool-midway/rpc';
|
||||
import { FileserverMonitorService } from './modules/center/service/fileserver-monitor';
|
||||
import { CenterLogService } from './modules/center/service/logstore';
|
||||
import { CenterNotifyWsService } from './modules/center/service/notify-ws';
|
||||
|
||||
@Configuration({
|
||||
imports: [
|
||||
@@ -77,7 +78,27 @@ export class MainConfiguration {
|
||||
logStore.start();
|
||||
}
|
||||
|
||||
/** HTTP server 起来后挂载通知 WebSocket(与 8800 共用端口,执行机 notifier.js 直连) */
|
||||
async onServerReady() {
|
||||
try {
|
||||
const framework: any = (this.app as any).getFramework?.();
|
||||
const server = typeof framework?.getServer === 'function' ? framework.getServer() : null;
|
||||
const wsService = await this.app.getApplicationContext().getAsync(CenterNotifyWsService);
|
||||
if (!wsService.attach(server)) {
|
||||
console.warn('[notify-ws] 未取到 http.Server,通知 WS 未启用(轮询兜底仍然可用)');
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.warn(`[notify-ws] 挂载异常:${e?.message || e}(轮询兜底仍然可用)`);
|
||||
}
|
||||
}
|
||||
|
||||
async onStop() {
|
||||
try {
|
||||
const wsService = await this.app.getApplicationContext().getAsync(CenterNotifyWsService);
|
||||
wsService.stop();
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
try {
|
||||
const monitor = await this.app.getApplicationContext().getAsync(FileserverMonitorService);
|
||||
monitor.stop();
|
||||
|
||||
Reference in New Issue
Block a user