From eedb556c06ae17bf5c8c0c9c7ff5085dd84fbfe6 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 Jul 2026 21:12:49 +0200 Subject: [PATCH] Feature/expose PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL environment variable (#7221) * Expose PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL environment variable * Update changelog --- CHANGELOG.md | 4 ++++ .../roai/portfolio-calculator-baln-buy-and-buy.spec.ts | 2 +- ...alculator-baln-buy-and-sell-in-two-activities.spec.ts | 2 +- .../roai/portfolio-calculator-baln-buy-and-sell.spec.ts | 2 +- .../roai/portfolio-calculator-baln-buy.spec.ts | 2 +- ...tfolio-calculator-btceur-in-base-currency-eur.spec.ts | 2 +- .../calculator/roai/portfolio-calculator-btceur.spec.ts | 2 +- ...olio-calculator-btcusd-buy-and-sell-partially.spec.ts | 2 +- .../roai/portfolio-calculator-btcusd-short.spec.ts | 2 +- .../calculator/roai/portfolio-calculator-btcusd.spec.ts | 2 +- .../calculator/roai/portfolio-calculator-cash.spec.ts | 2 +- .../calculator/roai/portfolio-calculator-fee.spec.ts | 2 +- .../roai/portfolio-calculator-googl-buy.spec.ts | 2 +- ...calculator-jnug-buy-and-sell-and-buy-and-sell.spec.ts | 2 +- .../roai/portfolio-calculator-liability.spec.ts | 2 +- .../roai/portfolio-calculator-msft-buy-and-sell.spec.ts | 2 +- .../portfolio-calculator-msft-buy-with-dividend.spec.ts | 2 +- .../roai/portfolio-calculator-no-orders.spec.ts | 2 +- ...tfolio-calculator-novn-buy-and-sell-partially.spec.ts | 2 +- .../roai/portfolio-calculator-novn-buy-and-sell.spec.ts | 2 +- .../roai/portfolio-calculator-valuable.spec.ts | 2 +- .../src/services/configuration/configuration.service.ts | 3 +++ .../api/src/services/interfaces/environment.interface.ts | 1 + .../portfolio-snapshot/portfolio-snapshot.service.ts | 9 ++++++++- 24 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13ae4176..227ced807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Exposed the `PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL` environment variable to control the removal of failed jobs in the portfolio snapshot computation queue + ### Changed - Upgraded `stripe` from version `21.0.1` to `22.2.3` diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-buy.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-buy.spec.ts index 9a93d0419..f21418cb4 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-buy.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts index c876d0db1..e2cba2e61 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts index ae921d6d9..fa397de46 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts index 6207f1417..db44fe0ae 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur-in-base-currency-eur.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur-in-base-currency-eur.spec.ts index 774c1d2f6..1afd9225d 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur-in-base-currency-eur.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur-in-base-currency-eur.spec.ts @@ -87,7 +87,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts index 055356325..0e5750166 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts @@ -75,7 +75,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts index 11765fc49..1e556735d 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts @@ -77,7 +77,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-short.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-short.spec.ts index 6a45f79c6..9d84540e3 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-short.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd-short.spec.ts @@ -75,7 +75,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts index 64882061f..0916e18a4 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts @@ -75,7 +75,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts index 2d85330a3..7774ee629 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts @@ -125,7 +125,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); portfolioCalculatorFactory = new PortfolioCalculatorFactory( configurationService, diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-fee.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-fee.spec.ts index a3fbc0758..b55c94b2b 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-fee.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-fee.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-googl-buy.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-googl-buy.spec.ts index 122a9aaed..bb61d637e 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-googl-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-googl-buy.spec.ts @@ -77,7 +77,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-jnug-buy-and-sell-and-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-jnug-buy-and-sell-and-buy-and-sell.spec.ts index d5b22e864..88afc971d 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-jnug-buy-and-sell-and-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-jnug-buy-and-sell-and-buy-and-sell.spec.ts @@ -78,7 +78,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-liability.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-liability.spec.ts index acbf6a66b..4f2058513 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-liability.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-liability.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-and-sell.spec.ts index baa6ae1ed..36d1ea1ec 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-and-sell.spec.ts @@ -60,7 +60,7 @@ describe('PortfolioCalculator', () => { null, null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); portfolioCalculatorFactory = new PortfolioCalculatorFactory( configurationService, diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts index e7eff6682..c50ef2b34 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-no-orders.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-no-orders.spec.ts index 6c47af7ca..30ebaa8c4 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-no-orders.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-no-orders.spec.ts @@ -60,7 +60,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell-partially.spec.ts index 3034e3a1f..cdfc78906 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell-partially.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell-partially.spec.ts @@ -78,7 +78,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts index c79fdef58..2cd754c82 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts @@ -78,7 +78,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-valuable.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-valuable.spec.ts index e518a5994..1d6cee0fa 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-valuable.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-valuable.spec.ts @@ -65,7 +65,7 @@ describe('PortfolioCalculator', () => { null ); - portfolioSnapshotService = new PortfolioSnapshotService(null); + portfolioSnapshotService = new PortfolioSnapshotService(null, null); redisCacheService = new RedisCacheService(null, null); diff --git a/apps/api/src/services/configuration/configuration.service.ts b/apps/api/src/services/configuration/configuration.service.ts index 703a90c3a..c96ccd946 100644 --- a/apps/api/src/services/configuration/configuration.service.ts +++ b/apps/api/src/services/configuration/configuration.service.ts @@ -96,6 +96,9 @@ export class ConfigurationService { PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_CONCURRENCY: num({ default: DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_CONCURRENCY }), + PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL: bool({ + default: true + }), PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT: num({ default: DEFAULT_PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT }), diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index 11bdeabf6..89463e201 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -47,6 +47,7 @@ export interface Environment extends CleanedEnvAccessors { PROCESSOR_GATHER_HISTORICAL_MARKET_DATA_CONCURRENCY: number; PROCESSOR_GATHER_STATISTICS_CONCURRENCY: number; PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_CONCURRENCY: number; + PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL: boolean; PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT: number; REDIS_DB: number; REDIS_HOST: string; diff --git a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.ts b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.ts index d7449a9cc..99fa5aca2 100644 --- a/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.ts +++ b/apps/api/src/services/queues/portfolio-snapshot/portfolio-snapshot.service.ts @@ -1,3 +1,4 @@ +import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE } from '@ghostfolio/common/config'; import { InjectQueue } from '@nestjs/bull'; @@ -9,6 +10,7 @@ import { PortfolioSnapshotQueueJob } from './interfaces/portfolio-snapshot-queue @Injectable() export class PortfolioSnapshotService { public constructor( + private readonly configurationService: ConfigurationService, @InjectQueue(PORTFOLIO_SNAPSHOT_COMPUTATION_QUEUE) private readonly portfolioSnapshotQueue: Queue ) {} @@ -22,7 +24,12 @@ export class PortfolioSnapshotService { name: string; opts?: JobOptions; }) { - return this.portfolioSnapshotQueue.add(name, data, opts); + return this.portfolioSnapshotQueue.add(name, data, { + ...opts, + removeOnFail: this.configurationService.get( + 'PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_REMOVE_ON_FAIL' + ) + }); } public async getJob(jobId: string) {