21 lines
573 B
TypeScript
21 lines
573 B
TypeScript
import { INestApplicationContext, Type } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { WorkerModule } from './worker.module';
|
|
|
|
type ContextFactory = (
|
|
module: Type<unknown>,
|
|
) => Promise<INestApplicationContext>;
|
|
|
|
export async function bootstrapWorker(
|
|
createContext: ContextFactory = (module) =>
|
|
NestFactory.createApplicationContext(module),
|
|
): Promise<INestApplicationContext> {
|
|
const app = await createContext(WorkerModule);
|
|
app.enableShutdownHooks();
|
|
return app;
|
|
}
|
|
|
|
if (require.main === module) {
|
|
void bootstrapWorker();
|
|
}
|