2024-05-14 15:28:20 +01:00
|
|
|
import { NestFactory } from '@nestjs/core';
|
|
|
|
import { isMainThread } from 'node:worker_threads';
|
|
|
|
import { MicroservicesModule } from 'src/app.module';
|
|
|
|
import { envName, serverVersion } from 'src/constants';
|
|
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|
|
|
import { WebSocketAdapter } from 'src/middleware/websocket.adapter';
|
2024-09-07 13:21:25 -04:00
|
|
|
import { isStartUpError } from 'src/utils/events';
|
2024-06-10 17:01:04 +01:00
|
|
|
import { otelStart } from 'src/utils/instrumentation';
|
2024-05-14 15:28:20 +01:00
|
|
|
|
2024-05-17 14:44:30 +01:00
|
|
|
export async function bootstrap() {
|
2024-06-10 17:01:04 +01:00
|
|
|
const otelPort = Number.parseInt(process.env.IMMICH_MICROSERVICES_METRICS_PORT ?? '8082');
|
|
|
|
|
|
|
|
otelStart(otelPort);
|
2024-05-14 15:28:20 +01:00
|
|
|
|
|
|
|
const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true });
|
|
|
|
const logger = await app.resolve(ILoggerRepository);
|
2024-06-05 17:07:47 -04:00
|
|
|
logger.setAppName('Microservices');
|
|
|
|
logger.setContext('Bootstrap');
|
2024-05-14 15:28:20 +01:00
|
|
|
app.useLogger(logger);
|
|
|
|
app.useWebSocketAdapter(new WebSocketAdapter(app));
|
|
|
|
|
2024-05-17 12:59:05 -04:00
|
|
|
await app.listen(0);
|
2024-05-14 15:28:20 +01:00
|
|
|
|
2024-05-17 12:59:05 -04:00
|
|
|
logger.log(`Immich Microservices is running [v${serverVersion}] [${envName}] `);
|
2024-05-14 15:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isMainThread) {
|
2024-05-17 14:44:30 +01:00
|
|
|
bootstrap().catch((error) => {
|
2024-09-07 13:21:25 -04:00
|
|
|
if (!isStartUpError(error)) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
throw error;
|
2024-05-14 15:28:20 +01:00
|
|
|
});
|
|
|
|
}
|