mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(server): run microservices in worker thread (#9426)
feat: start microservices in worker thread and add internal microservices for the server
This commit is contained in:
parent
3d5e55bdaa
commit
1ea55d642e
6 changed files with 79 additions and 17 deletions
32
server/src/workers/microservices.ts
Normal file
32
server/src/workers/microservices.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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';
|
||||
import { otelSDK } from 'src/utils/instrumentation';
|
||||
|
||||
const host = process.env.HOST;
|
||||
|
||||
export async function bootstrapMicroservices() {
|
||||
otelSDK.start();
|
||||
|
||||
const port = Number(process.env.MICROSERVICES_PORT) || 3002;
|
||||
const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true });
|
||||
const logger = await app.resolve(ILoggerRepository);
|
||||
logger.setAppName('ImmichMicroservices');
|
||||
logger.setContext('ImmichMicroservices');
|
||||
app.useLogger(logger);
|
||||
app.useWebSocketAdapter(new WebSocketAdapter(app));
|
||||
|
||||
await (host ? app.listen(port, host) : app.listen(port));
|
||||
|
||||
logger.log(`Immich Microservices is listening on ${await app.getUrl()} [v${serverVersion}] [${envName}] `);
|
||||
}
|
||||
|
||||
if (!isMainThread) {
|
||||
bootstrapMicroservices().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue