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 { loadWorkerProcessConfig } from '../../../libs/config/src/load-process-env';
|
||||
import {
|
||||
toSafeRuntimeSummary,
|
||||
type WorkerRuntimeConfig,
|
||||
} from '../../../libs/config/src/runtime-config';
|
||||
import { WorkerModule } from './worker.module';
|
||||
|
||||
interface BootstrapWorkerOptions {
|
||||
config: WorkerRuntimeConfig;
|
||||
logger?: NestApplicationOptions['logger'];
|
||||
}
|
||||
|
||||
export async function bootstrapWorker(
|
||||
options: BootstrapWorkerOptions,
|
||||
): Promise<INestApplicationContext> {
|
||||
const app = await NestFactory.createApplicationContext(WorkerModule, {
|
||||
logger: options.logger,
|
||||
});
|
||||
app.enableShutdownHooks();
|
||||
return app;
|
||||
}
|
||||
|
||||
async function runWorker(): Promise<void> {
|
||||
const config = loadWorkerProcessConfig();
|
||||
console.info('Worker 进程启动配置', toSafeRuntimeSummary(config));
|
||||
await bootstrapWorker({ config });
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
void runWorker();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class WorkerModule {}
|
||||
Reference in New Issue
Block a user