-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start microservices in worker thread and add internal microserv…
…ices for the server
- Loading branch information
1 parent
06402aa
commit 1f84c9a
Showing
5 changed files
with
61 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters