diff --git a/CHANGELOG.md b/CHANGELOG.md index 180306acd..52ca01d15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the usability of the create or update access dialog - Improved the loading indicator of the accounts table +- Exposed the concurrency of the portfolio snapshot calculation as an environment variable (`PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT`) - Improved the language localization for German (`de`) - Improved the language localization for Polish (`pl`) - Upgraded `prisma` from version `5.19.0` to `5.19.1` diff --git a/apps/api/src/services/configuration/configuration.service.ts b/apps/api/src/services/configuration/configuration.service.ts index 26ef38c0a..0f9246107 100644 --- a/apps/api/src/services/configuration/configuration.service.ts +++ b/apps/api/src/services/configuration/configuration.service.ts @@ -1,6 +1,7 @@ import { Environment } from '@ghostfolio/api/services/interfaces/environment.interface'; import { CACHE_TTL_NO_CACHE, + DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT, DEFAULT_ROOT_URL } from '@ghostfolio/common/config'; @@ -47,6 +48,9 @@ export class ConfigurationService { MAX_ACTIVITIES_TO_IMPORT: num({ default: Number.MAX_SAFE_INTEGER }), MAX_CHART_ITEMS: num({ default: 365 }), PORT: port({ default: 3333 }), + PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT: num({ + default: DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT + }), REDIS_DB: num({ default: 0 }), REDIS_HOST: str({ default: 'localhost' }), REDIS_PASSWORD: str({ default: '' }), diff --git a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.processor.ts b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.processor.ts index f8173559e..b3ef4eb88 100644 --- a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.processor.ts +++ b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.processor.ts @@ -8,6 +8,7 @@ import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.s import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { CACHE_TTL_INFINITE, + DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT, PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, PORTFOLIO_SNAPSHOT_QUEUE } from '@ghostfolio/common/config'; @@ -29,7 +30,14 @@ export class PortfolioSnapshotProcessor { private readonly redisCacheService: RedisCacheService ) {} - @Process({ concurrency: 1, name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME }) + @Process({ + concurrency: parseInt( + process.env.PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT ?? + DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT.toString(), + 10 + ), + name: PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME + }) public async calculatePortfolioSnapshot( job: Job ) { diff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.ts index 79fdf6d05..6fc5650cc 100644 --- a/libs/common/src/lib/config.ts +++ b/libs/common/src/lib/config.ts @@ -48,6 +48,7 @@ export const DEFAULT_CURRENCY = 'USD'; export const DEFAULT_DATE_FORMAT_MONTH_YEAR = 'MMM yyyy'; export const DEFAULT_LANGUAGE_CODE = 'en'; export const DEFAULT_PAGE_SIZE = 50; +export const DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT = 1; export const DEFAULT_ROOT_URL = 'https://localhost:4200'; // USX is handled separately