feat(GOV-009): 建立 NestJS 三进程基线
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import { type INestApplicationContext, type NestApplicationOptions } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
|
||||
import { loadSchedulerProcessConfig } from '../../../libs/config/src/load-process-env';
|
||||
import {
|
||||
toSafeRuntimeSummary,
|
||||
type SchedulerRuntimeConfig,
|
||||
} from '../../../libs/config/src/runtime-config';
|
||||
import { SchedulerModule } from './scheduler.module';
|
||||
|
||||
interface BootstrapSchedulerOptions {
|
||||
config: SchedulerRuntimeConfig;
|
||||
logger?: NestApplicationOptions['logger'];
|
||||
}
|
||||
|
||||
export async function bootstrapScheduler(
|
||||
options: BootstrapSchedulerOptions,
|
||||
): Promise<INestApplicationContext> {
|
||||
const app = await NestFactory.createApplicationContext(SchedulerModule, {
|
||||
logger: options.logger,
|
||||
});
|
||||
app.enableShutdownHooks();
|
||||
return app;
|
||||
}
|
||||
|
||||
async function runScheduler(): Promise<void> {
|
||||
const config = loadSchedulerProcessConfig();
|
||||
console.info('Scheduler 进程启动配置', toSafeRuntimeSummary(config));
|
||||
await bootstrapScheduler({ config });
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
void runScheduler();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class SchedulerModule {}
|
||||
Reference in New Issue
Block a user