From 9defc7f5f3a8a121697e7388da30409ceb741d56 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Fri, 29 Aug 2025 17:08:29 +0100 Subject: [PATCH] add enabled option to configuration --- .../DataGenerator/Program.cs | 6 +-- .../Configuration/BaseConfiguration.cs | 31 ++++++----- .../{MyDbContext.cs => SchedulerContext.cs} | 1 + .../Jobs/Jobs.cs | 53 ++++++++++++++++--- .../Program.cs | 2 +- .../appsettings.json | 2 +- 6 files changed, 72 insertions(+), 23 deletions(-) rename TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/{MyDbContext.cs => SchedulerContext.cs} (93%) diff --git a/TransactionProcessing.SchedulerService/DataGenerator/Program.cs b/TransactionProcessing.SchedulerService/DataGenerator/Program.cs index f88cd25..39ffdbf 100644 --- a/TransactionProcessing.SchedulerService/DataGenerator/Program.cs +++ b/TransactionProcessing.SchedulerService/DataGenerator/Program.cs @@ -104,8 +104,8 @@ private static async Task GenerateStatements(ITransactionDataGeneratorService g, private static async Task GenerateTransactions(ITransactionDataGeneratorService g, Guid estateId, CancellationToken cancellationToken){ // Set the date range - DateTime startDate = new DateTime(2025, 7, 2); //27/7 - DateTime endDate = new DateTime(2025, 8,27); // This is the date of the last generated transaction + DateTime startDate = new DateTime(2025, 8, 28); //27/7 + DateTime endDate = new DateTime(2025, 8,28); // This is the date of the last generated transaction Result> dateRangeResult = g.GenerateDateRange(startDate, endDate); if (dateRangeResult.IsFailed) @@ -149,7 +149,7 @@ private static async Task GenerateTransactions(ITransactionDataGeneratorService //dataToSend = DataToSend.Files; // Settlement - dataToSend = DataToSend.Settlement; + //dataToSend = DataToSend.Settlement; if (dataToSend == 0) { Console.WriteLine("No data to send"); diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Configuration/BaseConfiguration.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Configuration/BaseConfiguration.cs index 011968c..584395d 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Configuration/BaseConfiguration.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Configuration/BaseConfiguration.cs @@ -1,4 +1,4 @@ - public record BaseConfiguration( + public record ServiceConfiguration( String ClientId, String ClientSecret, String FileProcessorApi, @@ -8,45 +8,52 @@ String EventStoreAddress); - public class ReplayParkedQueueJobConfiguration { + public class BaseConfiguration { + public Boolean IsEnabled { get; set; } = true; + } + + public class ReplayParkedQueueJobConfiguration : BaseConfiguration + { } - public class MakeFloatCreditsJobConfiguration{ + public class MakeFloatCreditsJobConfiguration : BaseConfiguration + { public Guid EstateId { get; set; } public List DepositAmounts { get; set; } = new List(); } - public class DepositAmount{ + public class DepositAmount : BaseConfiguration + { public Guid ContractId { get; set; } public Guid ProductId { get; set; } public Decimal Amount { get; set; } } - public class UploadTransactionFileJobConfiguration - { + public class UploadTransactionFileJobConfiguration : BaseConfiguration +{ public Guid EstateId { get; set; } public Guid MerchantId { get; set; } public Guid UserId { get; set; } public List ContractsToInclude { get; set; } } - public class GenerateTransactionsJobConfiguration - { + public class GenerateTransactionsJobConfiguration : BaseConfiguration +{ public Guid EstateId { get; set; } public Guid MerchantId { get; set; } } - public class ProcessSettlementJobConfiguration - { + public class ProcessSettlementJobConfiguration : BaseConfiguration +{ public Guid EstateId { get; set; } public Guid MerchantId { get; set; } } - public class MerchantStatementJobConfiguration - { + public class MerchantStatementJobConfiguration : BaseConfiguration +{ public Guid EstateId { get; set; } public Guid MerchantId { get; set; } } diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/MyDbContext.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/SchedulerContext.cs similarity index 93% rename from TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/MyDbContext.cs rename to TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/SchedulerContext.cs index b0b95c2..acf5d5d 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/MyDbContext.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Database/SchedulerContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using TickerQ.EntityFrameworkCore.Configurations; namespace TransactionProcessing.SchedulerService.TickerQ.Database diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Jobs/Jobs.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Jobs/Jobs.cs index f54f116..baaf6c6 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Jobs/Jobs.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Jobs/Jobs.cs @@ -1,5 +1,6 @@ using EventStore.Client; using Microsoft.AspNetCore.SignalR; +using Microsoft.IdentityModel.Tokens; using SecurityService.Client; using Shared.General; using Shared.Logger; @@ -7,6 +8,7 @@ using TickerQ.Utilities.Base; using TickerQ.Utilities.Models; using TransactionProcessing.SchedulerService.DataGenerator; +using TransactionProcessing.SchedulerService.TickerQ.Database; using TransactionProcessor.Client; using TransactionProcessor.DataTransferObjects; using TransactionProcessor.DataTransferObjects.Responses.Contract; @@ -19,15 +21,18 @@ public class TickerFunctions private readonly ISecurityServiceClient SecurityServiceClient; private readonly ITransactionProcessorClient TransactionProcessorClient; private readonly Func BaseAddressFunc; + private readonly SchedulerContext SchedulerContext; private readonly ITransactionDataGeneratorService TransactionDataGeneratorService; - private readonly BaseConfiguration BaseConfiguration; + private readonly ServiceConfiguration BaseConfiguration; public TickerFunctions(ISecurityServiceClient securityServiceClient, ITransactionProcessorClient transactionProcessorClient, - Func baseAddressFunc) { + Func baseAddressFunc, + SchedulerContext schedulerContext) { this.SecurityServiceClient = securityServiceClient; this.TransactionProcessorClient = transactionProcessorClient; this.BaseAddressFunc = baseAddressFunc; + this.SchedulerContext = schedulerContext; // Get the base configuration this.BaseConfiguration= BuildBaseConfiguration(); @@ -51,7 +56,7 @@ protected ITransactionDataGeneratorService CreateTransactionDataGenerator(String return g; } - internal static BaseConfiguration BuildBaseConfiguration() { + internal static ServiceConfiguration BuildBaseConfiguration() { String? clientId = ConfigurationReader.GetValueOrDefault("BaseConfiguration", "ClientId", ""); String? clientSecret = ConfigurationReader.GetValueOrDefault("BaseConfiguration", "ClientSecret", ""); String? fileProcessorApi = ConfigurationReader.GetValueOrDefault("BaseConfiguration", "FileProcessorApi", ""); @@ -87,7 +92,7 @@ internal static BaseConfiguration BuildBaseConfiguration() { throw new InvalidOperationException("Configuration validation failed: " + String.Join(", ", validationErrors)); } - return new BaseConfiguration( + return new ServiceConfiguration( clientId, clientSecret, fileProcessorApi, @@ -97,8 +102,12 @@ internal static BaseConfiguration BuildBaseConfiguration() { } [TickerFunction(functionName: "Replay Parked Queue")] - public async Task ReplayParkedQueue(TickerFunctionContext tickerContext, CancellationToken ct) - { + public async Task ReplayParkedQueue(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) { + Logger.LogWarning("Replay Parked Queue Job is not enabled"); + return; + } + Result result = await Jobs.ReplayParkedQueues(this.BaseConfiguration.EventStoreAddress, ct); if (result.IsFailed) { @@ -108,8 +117,19 @@ public async Task ReplayParkedQueue(TickerFunctionContext tickerContext, Cancell Logger.LogWarning("Running Replay Parked Queue"); } + private Boolean IsJobEnabled(TConfiguration configuration) where TConfiguration : BaseConfiguration { + if (configuration == null) + return true; + return configuration.IsEnabled; + } + [TickerFunction(functionName: "Make Float Credits")] public async Task MakeFloatCredits(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) + { + Logger.LogWarning("Make Float Credits is not enabled"); + return; + } Result result = await Jobs.MakeFloatCredits(this.TransactionDataGeneratorService, tickerContext.Request, ct); if (result.IsFailed) @@ -123,6 +143,11 @@ public async Task MakeFloatCredits(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) + { + Logger.LogWarning("Upload Transaction File is not enabled"); + return; + } String name = tickerContext.Request.MerchantId.ToString() switch { "af4d7c7c-9b8d-4e58-a12a-28d3e0b89df6" => "Demo Merchant 2", @@ -141,6 +166,12 @@ public async Task UploadTransactionFile(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) + { + Logger.LogWarning("Process Merchant Settlement Job is not enabled"); + return; + } + String name = tickerContext.Request.MerchantId.ToString() switch { "af4d7c7c-9b8d-4e58-a12a-28d3e0b89df6" => "Demo Merchant 2", @@ -159,6 +190,11 @@ public async Task ProcessMerchantSettlement(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) + { + Logger.LogWarning("Generate Merchant Transactions Job is not enabled"); + return; + } String name = tickerContext.Request.MerchantId.ToString() switch { "af4d7c7c-9b8d-4e58-a12a-28d3e0b89df6" => "Demo Merchant 2", "ab1c99fb-1c6c-4694-9a32-b71be5d1da33" => "Demo Merchant 1", @@ -179,6 +215,11 @@ public async Task GenerateMerchantTransactions(TickerFunctionContext tickerContext, CancellationToken ct) { + if (this.IsJobEnabled(tickerContext.Request) == false) + { + Logger.LogWarning("Generate Merchant Logon Job is not enabled"); + return; + } String name = tickerContext.Request.MerchantId.ToString() switch { "af4d7c7c-9b8d-4e58-a12a-28d3e0b89df6" => "Demo Merchant 2", diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Program.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Program.cs index 1862044..4d80d22 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Program.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.TickerQ/Program.cs @@ -54,7 +54,7 @@ }; HttpClient httpClient = new HttpClient(httpClientHandler); -BaseConfiguration baseConfiguration = TickerFunctions.BuildBaseConfiguration(); +ServiceConfiguration baseConfiguration = TickerFunctions.BuildBaseConfiguration(); builder.Services.AddSingleton(baseConfiguration); builder.Services.AddSingleton(httpClient); diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json index c81bdbf..cb534ed 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json @@ -7,7 +7,7 @@ } }, "ConnectionStrings": { - "Quartz": "server=127.0.0.1;user id=sa;password=sp1ttal;database=Scheduler;Encrypt=True;TrustServerCertificate=True" + "Quartz": "server=127.0.0.1;user id=sa;password=sp1ttal;database=Scheduler_new;Encrypt=True;TrustServerCertificate=True" }, //"Quartz": { // "quartz.scheduler.instanceName": "Txn Processing Scheduler",