-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): run microservices in worker thread (#9426)
feat: start microservices in worker thread and add internal microservices for the server
- Loading branch information
1 parent
3d5e55b
commit 1ea55d6
Showing
6 changed files
with
79 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,17 @@ | ||
type ColorTextFn = (text: string) => string; | ||
|
||
const isColorAllowed = () => !process.env.NO_COLOR; | ||
const colorIfAllowed = (colorFn: ColorTextFn) => (text: string) => (isColorAllowed() ? colorFn(text) : text); | ||
|
||
export const LogColor = { | ||
red: colorIfAllowed((text: string) => `\u001B[31m${text}\u001B[39m`), | ||
green: colorIfAllowed((text: string) => `\u001B[32m${text}\u001B[39m`), | ||
yellow: colorIfAllowed((text: string) => `\u001B[33m${text}\u001B[39m`), | ||
blue: colorIfAllowed((text: string) => `\u001B[34m${text}\u001B[39m`), | ||
magentaBright: colorIfAllowed((text: string) => `\u001B[95m${text}\u001B[39m`), | ||
cyanBright: colorIfAllowed((text: string) => `\u001B[96m${text}\u001B[39m`), | ||
}; | ||
|
||
export const LogStyle = { | ||
bold: colorIfAllowed((text: string) => `\u001B[1m${text}\u001B[0m`), | ||
}; |
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