fix(GOV-009): 完成脚手架审查整改

This commit is contained in:
2026-08-13 18:30:57 +08:00
parent dcdf634457
commit 3a8120a33a
47 changed files with 752 additions and 101 deletions
+8 -4
View File
@@ -2,35 +2,39 @@ import 'reflect-metadata';
import { type INestApplicationContext, type NestApplicationOptions } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import path from 'node:path';
import { loadSchedulerProcessConfig } from '../../../libs/config/src/load-process-env';
import {
toSafeRuntimeSummary,
type SchedulerRuntimeConfig,
} from '../../../libs/config/src/runtime-config';
import { waitForShutdownSignal } from '../../../libs/infrastructure/src/process-lifecycle';
import { SchedulerModule } from './scheduler.module';
/** Scheduler 引导参数确保模块只读取本进程已校验的最小配置。 */
interface BootstrapSchedulerOptions {
config: SchedulerRuntimeConfig;
logger?: NestApplicationOptions['logger'];
}
/** 启动无 HTTP 端口的 Scheduler 应用上下文,生命周期由命令入口持有。 */
export async function bootstrapScheduler(
options: BootstrapSchedulerOptions,
): Promise<INestApplicationContext> {
const app = await NestFactory.createApplicationContext(SchedulerModule, {
const app = await NestFactory.createApplicationContext(SchedulerModule.register(options.config), {
logger: options.logger,
});
app.enableShutdownHooks();
return app;
}
async function runScheduler(): Promise<void> {
const config = loadSchedulerProcessConfig();
console.info('Scheduler 进程启动配置', toSafeRuntimeSummary(config));
await bootstrapScheduler({ config });
const app = await bootstrapScheduler({ config });
await waitForShutdownSignal(app);
}
if (require.main === module) {
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(__filename)) {
void runScheduler();
}
+16 -2
View File
@@ -1,4 +1,18 @@
import { Module } from '@nestjs/common';
import { type DynamicModule, Module } from '@nestjs/common';
import type { SchedulerRuntimeConfig } from '../../../libs/config/src/runtime-config';
/** Scheduler 的最小权限配置令牌,不向 API 或 Worker 暴露其任务调度配置。 */
export const SCHEDULER_RUNTIME_CONFIG = Symbol('SCHEDULER_RUNTIME_CONFIG');
@Module({})
export class SchedulerModule {}
export class SchedulerModule {
/** 将入口校验后的 Scheduler 配置注册进当前进程容器。 */
static register(config: SchedulerRuntimeConfig): DynamicModule {
return {
module: SchedulerModule,
providers: [{ provide: SCHEDULER_RUNTIME_CONFIG, useValue: config }],
exports: [SCHEDULER_RUNTIME_CONFIG],
};
}
}