refactor(server): bootstrap code (#2682)

* refactor(server): bootstrap code

* Add service name

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
Jason Rasmussen 2023-06-07 10:56:08 -04:00 committed by GitHub
parent eb1225a0a5
commit d08535e7f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 46 deletions

View file

@ -4,41 +4,20 @@ import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppService } from './app.service';
import { MicroservicesModule } from './microservices.module';
import { MetadataExtractionProcessor } from './processors/metadata-extraction.processor';
const logger = new Logger('ImmichMicroservice');
const port = Number(process.env.MICROSERVICES_PORT) || 3002;
const envName = (process.env.NODE_ENV || 'development').toUpperCase();
async function bootstrap() {
const app = await NestFactory.create(MicroservicesModule, {
logger: getLogLevels(),
});
const listeningPort = Number(process.env.MICROSERVICES_PORT) || 3002;
await app.get(AppService).init();
const app = await NestFactory.create(MicroservicesModule, { logger: getLogLevels() });
app.useWebSocketAdapter(new RedisIoAdapter(app));
const metadataService = app.get(MetadataExtractionProcessor);
await app.get(AppService).init();
await app.listen(port);
process.on('uncaughtException', (error: Error | any) => {
const isCsvError = error.code === 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH';
if (!isCsvError) {
throw error;
}
logger.warn('Geocoding csv parse error, trying again without cache...');
metadataService.init(true);
});
await metadataService.init();
await app.listen(listeningPort, () => {
const envName = (process.env.NODE_ENV || 'development').toUpperCase();
logger.log(
`Running Immich Microservices in ${envName} environment - version ${SERVER_VERSION} - Listening on port: ${listeningPort}`,
);
});
logger.log(`Immich Microservices is listening on ${port} [v${SERVER_VERSION}] [${envName}] `);
}
bootstrap();