From 1896289bc9b416a8b87b7543e62e13e3a14c9155 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 21 Jun 2026 10:22:29 +0200 Subject: [PATCH] Feature/expose ENABLE_FEATURE_CRON environment variable (#7090) * Expose ENABLE_FEATURE_CRON environment variable * Update changelog --- CHANGELOG.md | 4 ++ .../configuration/configuration.service.ts | 1 + apps/api/src/services/cron/cron.module.ts | 49 ++++++++++++++++++- .../interfaces/environment.interface.ts | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5dd293bb..41bf233c0 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 `ENABLE_FEATURE_CRON` environment variable to control scheduled cron job execution + ### Changed - Improved the language localization for German (`de`) diff --git a/apps/api/src/services/configuration/configuration.service.ts b/apps/api/src/services/configuration/configuration.service.ts index 5f9d1055d..328620164 100644 --- a/apps/api/src/services/configuration/configuration.service.ts +++ b/apps/api/src/services/configuration/configuration.service.ts @@ -43,6 +43,7 @@ export class ConfigurationService { ENABLE_FEATURE_AUTH_GOOGLE: bool({ default: false }), ENABLE_FEATURE_AUTH_OIDC: bool({ default: false }), ENABLE_FEATURE_AUTH_TOKEN: bool({ default: true }), + ENABLE_FEATURE_CRON: bool({ default: true }), ENABLE_FEATURE_FEAR_AND_GREED_INDEX: bool({ default: false }), ENABLE_FEATURE_GATHER_NEW_EXCHANGE_RATES: bool({ default: true }), ENABLE_FEATURE_READ_ONLY_MODE: bool({ default: false }), diff --git a/apps/api/src/services/cron/cron.module.ts b/apps/api/src/services/cron/cron.module.ts index bcc9d3360..3d999e397 100644 --- a/apps/api/src/services/cron/cron.module.ts +++ b/apps/api/src/services/cron/cron.module.ts @@ -1,12 +1,19 @@ import { UserModule } from '@ghostfolio/api/app/user/user.module'; +import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.module'; +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; +import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { DataGatheringQueueModule } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.module'; +import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service'; import { StatisticsGatheringQueueModule } from '@ghostfolio/api/services/queues/statistics-gathering/statistics-gathering.module'; +import { StatisticsGatheringService } from '@ghostfolio/api/services/queues/statistics-gathering/statistics-gathering.service'; import { TwitterBotModule } from '@ghostfolio/api/services/twitter-bot/twitter-bot.module'; +import { TwitterBotService } from '@ghostfolio/api/services/twitter-bot/twitter-bot.service'; -import { Module } from '@nestjs/common'; +import { Logger, Module } from '@nestjs/common'; import { CronService } from './cron.service'; @@ -20,6 +27,44 @@ import { CronService } from './cron.service'; TwitterBotModule, UserModule ], - providers: [CronService] + providers: [ + { + inject: [ + ConfigurationService, + DataGatheringService, + ExchangeRateDataService, + PropertyService, + StatisticsGatheringService, + TwitterBotService, + UserService + ], + provide: CronService, + useFactory: ( + configurationService: ConfigurationService, + dataGatheringService: DataGatheringService, + exchangeRateDataService: ExchangeRateDataService, + propertyService: PropertyService, + statisticsGatheringService: StatisticsGatheringService, + twitterBotService: TwitterBotService, + userService: UserService + ) => { + if (!configurationService.get('ENABLE_FEATURE_CRON')) { + Logger.log('Scheduled cron jobs are disabled', 'CronService'); + + return null; + } + + return new CronService( + configurationService, + dataGatheringService, + exchangeRateDataService, + propertyService, + statisticsGatheringService, + twitterBotService, + userService + ); + } + } + ] }) export class CronModule {} diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index 57c58898e..45654a2e3 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -19,6 +19,7 @@ export interface Environment extends CleanedEnvAccessors { ENABLE_FEATURE_AUTH_GOOGLE: boolean; ENABLE_FEATURE_AUTH_OIDC: boolean; ENABLE_FEATURE_AUTH_TOKEN: boolean; + ENABLE_FEATURE_CRON: boolean; ENABLE_FEATURE_FEAR_AND_GREED_INDEX: boolean; ENABLE_FEATURE_GATHER_NEW_EXCHANGE_RATES: boolean; ENABLE_FEATURE_READ_ONLY_MODE: boolean;