mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
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:
parent
eb1225a0a5
commit
d08535e7f6
4 changed files with 35 additions and 46 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue