diff --git a/back/src/Liane/Liane.Api/Util/CronJobService.cs b/back/src/Liane/Liane.Api/Util/CronJobService.cs index cc489eba5..ce191eae4 100644 --- a/back/src/Liane/Liane.Api/Util/CronJobService.cs +++ b/back/src/Liane/Liane.Api/Util/CronJobService.cs @@ -15,17 +15,24 @@ public abstract class CronJobService : IHostedService, IDisposable private readonly TimeZoneInfo timeZoneInfo; private readonly bool runImmediately; private readonly ILogger logger; + private readonly bool isEnabled; - protected CronJobService(ILogger logger, string cronExpression, bool runImmediately) + protected CronJobService(ILogger logger, string cronExpression, bool runImmediately, bool isEnabled = true) { this.logger = logger; expression = CronExpression.Parse(cronExpression); this.runImmediately = runImmediately; timeZoneInfo = TimeZoneInfo.Local; + this.isEnabled = isEnabled; } public virtual async Task StartAsync(CancellationToken cancellationToken) { + if (!isEnabled) + { + return; + } + try { await ScheduleJob(cancellationToken); @@ -87,6 +94,11 @@ private async Task ScheduleJob(CancellationToken cancellationToken) public virtual async Task StopAsync(CancellationToken cancellationToken) { + if (!isEnabled) + { + return; + } + logger.LogInformation("{job} stopped", GetType().Name); timer?.Stop(); await Task.CompletedTask; diff --git a/back/src/Liane/Liane.Mock/GeneratorSettings.cs b/back/src/Liane/Liane.Mock/GeneratorSettings.cs new file mode 100644 index 000000000..ac938e19a --- /dev/null +++ b/back/src/Liane/Liane.Mock/GeneratorSettings.cs @@ -0,0 +1,3 @@ +namespace Liane.Mock; + +public sealed record GeneratorSettings(bool IsEnabled); \ No newline at end of file diff --git a/back/src/Liane/Liane.Mock/LianeMockGenerator.cs b/back/src/Liane/Liane.Mock/LianeMockGenerator.cs index 7d546ba4c..f4dee6ca5 100644 --- a/back/src/Liane/Liane.Mock/LianeMockGenerator.cs +++ b/back/src/Liane/Liane.Mock/LianeMockGenerator.cs @@ -12,7 +12,7 @@ public sealed class LianeMockGenerator : CronJobService private readonly IMockService mockService; private readonly ILogger logger; - public LianeMockGenerator(ILogger logger, IMockService mockService) : base(logger, CronExpression, false) + public LianeMockGenerator(ILogger logger, IMockService mockService, GeneratorSettings settings) : base(logger, CronExpression, false, settings.IsEnabled) { this.logger = logger; this.mockService = mockService; diff --git a/back/src/Liane/Liane.Web/Internal/Debug/RequestLoggerFilter.cs b/back/src/Liane/Liane.Web/Internal/Debug/RequestLoggerFilter.cs index 565b85794..6ebdafd38 100644 --- a/back/src/Liane/Liane.Web/Internal/Debug/RequestLoggerFilter.cs +++ b/back/src/Liane/Liane.Web/Internal/Debug/RequestLoggerFilter.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -using MongoDB.Driver.Core.Operations; namespace Liane.Web.Internal.Debug; diff --git a/back/src/Liane/Liane.Web/Startup.cs b/back/src/Liane/Liane.Web/Startup.cs index 9209ac9f3..62aa0d78a 100755 --- a/back/src/Liane/Liane.Web/Startup.cs +++ b/back/src/Liane/Liane.Web/Startup.cs @@ -99,6 +99,7 @@ private static void ConfigureLianeServices(WebHostBuilderContext context, IServi services.AddService(); + services.AddSettings(context); services.AddHostedService(); services.AddHostedService(); diff --git a/back/src/Liane/Liane.Web/default.json b/back/src/Liane/Liane.Web/default.json index f499a20c9..76b94217e 100755 --- a/back/src/Liane/Liane.Web/default.json +++ b/back/src/Liane/Liane.Web/default.json @@ -15,5 +15,8 @@ "Validity": "0.08:00:00", "Issuer": "Liane", "Audience": "Liane" + }, + "Generator": { + "IsEnabled": false } } diff --git a/deploy/liane.yml b/deploy/liane.yml index eef8d073d..7928eaa51 100644 --- a/deploy/liane.yml +++ b/deploy/liane.yml @@ -85,6 +85,7 @@ services: LIANE_Cloudflare__AccountId: ${CLOUDFLARE_ACCOUNT_ID} LIANE_Cloudflare__AccountHash: ${CLOUDFLARE_ACCOUNT_HASH} LIANE_Cloudflare__ApiKey: ${CLOUDFLARE_API_KEY} + LIANE_Generator__IsEnabled: ${GENERATOR_IS_ENABLED} restart: unless-stopped networks: - gateway