Browse Source

Feature/expose portfolio snapshot calculation timeout as environment variable

Expose `PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT` env var to allow people to configure the `lockDuration` option for the Portfolio Snapshot queue. `@nodejs/bull`'s default is 30s, so if a job holds the JS event loop longer than that it gets marked as stalled ([reference](https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#advanced-settings)). The end-user experience right now for when that happens is that the ghostfolio container crashes.

Test Plan:
1. Before this diff, my container always crashes since my portfolio snapshot computation takes about 2 minutes
2. Apply this diff, set `PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT` to 5 minutes (`300000`)
3. Open Accounts page to trigger portfolio snapshot computation
4. Check it no longer crashes
pull/3894/head
ceroma 11 months ago
committed by Thomas Kaul
parent
commit
49543548a1
  1. 4
      apps/api/src/services/configuration/configuration.service.ts
  2. 14
      apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.module.ts
  3. 1
      libs/common/src/lib/config.ts

4
apps/api/src/services/configuration/configuration.service.ts

@ -4,6 +4,7 @@ import {
DEFAULT_PROCESSOR_CONCURRENCY_GATHER_ASSET_PROFILE,
DEFAULT_PROCESSOR_CONCURRENCY_GATHER_HISTORICAL_MARKET_DATA,
DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT,
DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT,
DEFAULT_ROOT_URL
} from '@ghostfolio/common/config';
@ -59,6 +60,9 @@ export class ConfigurationService {
PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT: num({
default: DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT
}),
PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT: num({
default: DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT
}),
REDIS_DB: num({ default: 0 }),
REDIS_HOST: str({ default: 'localhost' }),
REDIS_PASSWORD: str({ default: '' }),

14
apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.module.ts

@ -8,7 +8,10 @@ import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.module';
import { MarketDataModule } from '@ghostfolio/api/services/market-data/market-data.module';
import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service';
import { PORTFOLIO_SNAPSHOT_QUEUE } from '@ghostfolio/common/config';
import {
PORTFOLIO_SNAPSHOT_QUEUE,
DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT
} from '@ghostfolio/common/config';
import { BullModule } from '@nestjs/bull';
import { Module } from '@nestjs/common';
@ -20,7 +23,14 @@ import { PortfolioSnapshotProcessor } from './portfolio-snapshot.processor';
imports: [
AccountBalanceModule,
BullModule.registerQueue({
name: PORTFOLIO_SNAPSHOT_QUEUE
name: PORTFOLIO_SNAPSHOT_QUEUE,
settings: {
lockDuration: parseInt(
process.env.PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT ??
DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT.toString(),
10
)
}
}),
ConfigurationModule,
DataProviderModule,

1
libs/common/src/lib/config.ts

@ -51,6 +51,7 @@ export const DEFAULT_PAGE_SIZE = 50;
export const DEFAULT_PROCESSOR_CONCURRENCY_GATHER_ASSET_PROFILE = 1;
export const DEFAULT_PROCESSOR_CONCURRENCY_GATHER_HISTORICAL_MARKET_DATA = 1;
export const DEFAULT_PROCESSOR_CONCURRENCY_PORTFOLIO_SNAPSHOT = 1;
export const DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT = 30000;
export const DEFAULT_ROOT_URL = 'https://localhost:4200';
// USX is handled separately

Loading…
Cancel
Save