import { INestApplicationContext } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { resolveRole } from './runtime/role'; import { assertStartupEnvironment } from './runtime/startup-checks'; import { WorkerModule } from './worker/worker.module'; /** * Entry point of the worker role: domain events, calendar outbox and their * wake-ups, plus GET /health on WORKER_HEALTH_PORT - no HTTP API. Role and * environment are checked before any module is created, so a misconfigured * pod fails before it connects anywhere. `env` is for tests; the modules * themselves read process.env. */ export async function bootstrapWorker( env: NodeJS.ProcessEnv = process.env, ): Promise { const role = resolveRole('worker', env); assertStartupEnvironment(role, env); const app = await NestFactory.createApplicationContext(WorkerModule); app.enableShutdownHooks(); return app; } // Started as `node dist/worker.js`; importing this file starts nothing. if (require.main === module) { void bootstrapWorker(); }