diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/BaseConfiguration.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/BaseConfiguration.cs index 90dcc9f..7ee8ef0 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/BaseConfiguration.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/BaseConfiguration.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/FileUploadJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/FileUploadJobConfig.cs index ca11155..8df4a19 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/FileUploadJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/FileUploadJobConfig.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MakeFloatCreditsJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MakeFloatCreditsJobConfig.cs index e9f3aed..61df8d3 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MakeFloatCreditsJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MakeFloatCreditsJobConfig.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MerchantStatementJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MerchantStatementJobConfig.cs index e879a65..5857a40 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MerchantStatementJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/MerchantStatementJobConfig.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/ReplayParkedQueueJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/ReplayParkedQueueJobConfig.cs index b1eed8d..fb5f163 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/ReplayParkedQueueJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/ReplayParkedQueueJobConfig.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/SettlementJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/SettlementJobConfig.cs index 4a46381..104bb50 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/SettlementJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/SettlementJobConfig.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/TransactionJobConfig.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/TransactionJobConfig.cs index 076c6b2..ffd26fa 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/TransactionJobConfig.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Configuration/TransactionJobConfig.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Microsoft.Extensions.Logging; namespace TransactionProcessing.SchedulerService.Jobs.Configuration; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/BaseJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/BaseJob.cs index dae8be6..137faa1 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/BaseJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/BaseJob.cs @@ -1,14 +1,17 @@ using System; using System.Threading; using System.Threading.Tasks; +using NLog; using Quartz; using SecurityService.Client; using SecurityService.DataTransferObjects.Responses; -using Shared.Logger; +using SimpleResults; using TransactionProcessing.SchedulerService.DataGenerator; using TransactionProcessing.SchedulerService.Jobs.Common; using TransactionProcessing.SchedulerService.Jobs.Configuration; using TransactionProcessor.Client; +using Logger = Shared.Logger.Logger; +using LogLevel = Microsoft.Extensions.Logging.LogLevel; namespace TransactionProcessing.SchedulerService.Jobs.Jobs; @@ -34,19 +37,11 @@ protected ITransactionDataGeneratorService CreateTransactionDataGenerator(String runningMode); return g; } - - //protected async Task GetToken(String clientId, String clientSecret, CancellationToken cancellationToken) - //{ - // ISecurityServiceClient securityServiceClient = Bootstrapper.GetService(); - // TokenResponse token = await securityServiceClient.GetToken(clientId, clientSecret, cancellationToken); - - // return token.AccessToken; - //} - + protected void TraceGenerated(TraceEventArgs traceArguments) { if (traceArguments.TraceLevel == TraceEventArgs.Level.Error){ - Logger.LogError(new Exception(traceArguments.Message)); + Logger.LogError(traceArguments.Message, null); } else if (traceArguments.TraceLevel == TraceEventArgs.Level.Warning){ Logger.LogWarning(traceArguments.Message); @@ -56,19 +51,21 @@ protected void TraceGenerated(TraceEventArgs traceArguments) } } - public abstract Task ExecuteJob(IJobExecutionContext context); + public abstract Task ExecuteJob(IJobExecutionContext context); public async Task Execute(IJobExecutionContext context){ this.CacheConfiguration(context); - Logger.LogInformation($"Running Job Group: [{this.JobGroup}] Name: [{this.JobName}]"); - //this.LogConfiguration(); - + Logger.LogWarning($"Running Job Group: [{this.JobGroup}] Name: [{this.JobName}]"); + Bootstrapper.ConfigureServices(context, this.BaseConfiguration); + Result result = await this.ExecuteJob(context); + if (result.IsFailed){ + Logger.LogWarning($"Job Group: [{this.JobGroup}] Name: [{this.JobName}] failed. Exception {result.Message}"); + throw new JobExecutionException(result.Message); + } - await this.ExecuteJob(context); - - Logger.LogInformation($"Job Group: [{this.JobGroup}] Name: [{this.JobName}] completed"); + Logger.LogWarning($"Job Group: [{this.JobGroup}] Name: [{this.JobName}] completed"); } private void CacheConfiguration(IJobExecutionContext context){ diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateFileUploadsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateFileUploadsJob.cs index 05a9327..7a24909 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateFileUploadsJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateFileUploadsJob.cs @@ -5,25 +5,24 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs { - using System; - using System.Threading.Tasks; using Quartz; using Shared.Logger; + using SimpleResults; + using System; + using System.Threading.Tasks; using TransactionProcessing.SchedulerService.Jobs.Jobs; [DisallowConcurrentExecution] public class GenerateFileUploadsJob : BaseJob { #region Methods - public override async Task ExecuteJob(IJobExecutionContext context) + public override async Task ExecuteJob(IJobExecutionContext context) { FileUploadJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); ITransactionDataGeneratorService t = CreateTransactionDataGenerator(configuration.ClientId, configuration.ClientSecret, RunningMode.Live); t.TraceGenerated += TraceGenerated; - var result = await Jobs.GenerateFileUploads(t, configuration, context.CancellationToken); - if (result.IsFailed) - throw new JobExecutionException(result.Message); + return await Jobs.GenerateFileUploads(t, configuration, context.CancellationToken); } #endregion } diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateMerchantStatementJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateMerchantStatementJob.cs index 826c2b7..d7ae36f 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateMerchantStatementJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateMerchantStatementJob.cs @@ -4,22 +4,21 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs; -using System; -using System.Threading.Tasks; using Quartz; using Shared.Logger; +using SimpleResults; +using System; +using System.Threading.Tasks; using TransactionProcessing.SchedulerService.Jobs.Jobs; public class GenerateMerchantStatementJob : BaseJob { - public override async Task ExecuteJob(IJobExecutionContext context) + public override async Task ExecuteJob(IJobExecutionContext context) { MerchantStatementJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); ITransactionDataGeneratorService t = CreateTransactionDataGenerator(configuration.ClientId, configuration.ClientSecret, RunningMode.Live); t.TraceGenerated += TraceGenerated; - var result = await Jobs.GenerateMerchantStatements(t, configuration, context.CancellationToken); - if (result.IsFailed) - throw new JobExecutionException(result.Message); + return await Jobs.GenerateMerchantStatements(t, configuration, context.CancellationToken); } } \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateTransactionsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateTransactionsJob.cs index e035ad7..24ffea5 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateTransactionsJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/GenerateTransactionsJob.cs @@ -3,10 +3,11 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs { - using System.Text.Json.Nodes; - using System.Threading.Tasks; using Quartz; using Shared.Logger; + using SimpleResults; + using System.Text.Json.Nodes; + using System.Threading.Tasks; using TransactionProcessing.SchedulerService.DataGenerator; using TransactionProcessing.SchedulerService.Jobs.Jobs; @@ -19,16 +20,14 @@ public class GenerateTransactionsJob : BaseJob #region Methods - public override async Task ExecuteJob(IJobExecutionContext context) + public override async Task ExecuteJob(IJobExecutionContext context) { TransactionJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); ITransactionDataGeneratorService t = CreateTransactionDataGenerator(configuration.ClientId, configuration.ClientSecret, RunningMode.Live); t.TraceGenerated += TraceGenerated; - var result = await Jobs.GenerateTransactions(t, configuration, context.CancellationToken); - if (result.IsFailed) - throw new JobExecutionException(result.Message); + return await Jobs.GenerateTransactions(t, configuration, context.CancellationToken); } #endregion } diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/Jobs.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/Jobs.cs index 0900ce3..e4aa1e8 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/Jobs.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/Jobs.cs @@ -25,77 +25,72 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs; using Quartz; using Shared.Logger; -public static class Jobs -{ - public static async Task GenerateMerchantStatements(ITransactionDataGeneratorService t, MerchantStatementJobConfig config, CancellationToken cancellationToken) - { +public static class Jobs { + public static async Task GenerateMerchantStatements(ITransactionDataGeneratorService t, + MerchantStatementJobConfig config, + CancellationToken cancellationToken) { var getMerchantsResult = await t.GetMerchants(config.EstateId, cancellationToken); - if (getMerchantsResult.IsFailed) - { + if (getMerchantsResult.IsFailed) { return Result.Failure($"No merchants returned for Estate [{config.EstateId}]"); } var merchants = getMerchantsResult.Data; List results = new(); - foreach (MerchantResponse merchantResponse in merchants) - { + foreach (MerchantResponse merchantResponse in merchants) { Result result = await t.GenerateMerchantStatement(merchantResponse.EstateId, merchantResponse.MerchantId, DateTime.Now, cancellationToken); - if (result.IsFailed) - { + if (result.IsFailed) { results.Add(merchantResponse.MerchantName); } } - if (results.Any()) - { + if (results.Any()) { return Result.Failure($"Error generating statements for merchants [{string.Join(",", results)}]"); } + return Result.Success(); } - public static async Task GenerateFileUploads(ITransactionDataGeneratorService t, FileUploadJobConfig config, CancellationToken cancellationToken) - { + public static async Task GenerateFileUploads(ITransactionDataGeneratorService t, + FileUploadJobConfig config, + CancellationToken cancellationToken) { Result merchantResult = await t.GetMerchant(config.EstateId, config.MerchantId, cancellationToken); - if (merchantResult.IsFailed) - { + if (merchantResult.IsFailed) { return Result.Failure($"No merchant returned for Estate Id [{config.EstateId}] Merchant Id [{config.MerchantId}]"); } MerchantResponse merchant = merchantResult.Data; Result> getMerchantContractsResult = await t.GetMerchantContracts(merchant, cancellationToken); - if (getMerchantContractsResult.IsFailed) - { + if (getMerchantContractsResult.IsFailed) { Console.WriteLine($"Failed to get merchant contracts: {getMerchantContractsResult.Message}"); return Result.Failure(); } + DateTime fileDate = DateTime.Now.Date; List results = new List(); - foreach (ContractResponse contract in getMerchantContractsResult.Data) - { + foreach (ContractResponse contract in getMerchantContractsResult.Data) { if (config.ContractNames.Contains(contract.Description) == false) continue; // Generate a file and upload Result result = await t.SendUploadFile(fileDate, contract, merchant, config.UserId, cancellationToken); - if (result.IsFailed) - { + if (result.IsFailed) { results.Add(contract.OperatorName); } } - if (results.Any()) - { + if (results.Any()) { return Result.Failure($"Error uploading files for merchant [{merchant.MerchantName}] [{string.Join(",", results)}]"); } + return Result.Success(); } public static async Task GenerateFloatCredits(ITransactionDataGeneratorService t, - MakeFloatCreditsJobConfig config, - CancellationToken cancellationToken) { + MakeFloatCreditsJobConfig config, + CancellationToken cancellationToken) { List results = new(); // Get all the contracts up front Result> contractsResult = await t.GetEstateContracts(config.EstateId, cancellationToken); @@ -111,35 +106,33 @@ public static async Task GenerateFloatCredits(ITransactionDataGeneratorS results.Add($"Contract Name {configDepositAmount.ContractName} not found"); continue; } - - ContractProduct product = contract.Products.SingleOrDefault(p => p.Name== configDepositAmount.ProductName); - if (product == null) - { + + ContractProduct product = contract.Products.SingleOrDefault(p => p.Name == configDepositAmount.ProductName); + if (product == null) { results.Add($"Contract Name {configDepositAmount.ContractName} Product {configDepositAmount.ProductName} not found"); continue; } - Result result = await t.MakeFloatDeposit(DateTime.Now, config.EstateId, contract.ContractId, - product.ProductId, configDepositAmount.Amount, cancellationToken); - if (result.IsFailed) - { + Result result = await t.MakeFloatDeposit(DateTime.Now, config.EstateId, contract.ContractId, product.ProductId, configDepositAmount.Amount, cancellationToken); + if (result.IsFailed) { results.Add($"Contract Id {contract.ContractId} Product Id {product.ProductId}"); } } - if (results.Any()) - { + + if (results.Any()) { return Result.Failure($"Error making float credits for [{string.Join(",", results)}]"); } + return Result.Success(); } - public static async Task GenerateTransactions(ITransactionDataGeneratorService t, TransactionJobConfig config, CancellationToken cancellationToken) - { + public static async Task GenerateTransactions(ITransactionDataGeneratorService t, + TransactionJobConfig config, + CancellationToken cancellationToken) { // get the merchant Result merchantResult = await t.GetMerchant(config.EstateId, config.MerchantId, cancellationToken); - if (merchantResult.IsFailed) - { + if (merchantResult.IsFailed) { return Result.Failure($"Error getting Merchant Id [{config.MerchantId}] for Estate Id [{config.EstateId}]"); } @@ -149,33 +142,30 @@ public static async Task GenerateTransactions(ITransactionDataGeneratorS // Get the merchants contracts Result> contractResult = await t.GetMerchantContracts(merchant, cancellationToken); - + if (contractResult.IsFailed) { return Result.Failure($"Error getting contracts for Merchant [{merchant.MerchantName}]"); } List contracts = contractResult.Data; - if (contracts.Any() == false) - { + if (contracts.Any() == false) { return Result.Failure($"No contracts returned for Merchant [{merchant.MerchantName}]"); } - if (config.IsLogon) - { + if (config.IsLogon) { // Do a logon transaction for the merchant Result logonResult = await t.PerformMerchantLogon(transactionDate, merchant, cancellationToken); - if (logonResult.IsFailed) - { + if (logonResult.IsFailed) { return Result.Failure($"Error performing logon for Merchant [{merchant.MerchantName}]"); } + return Result.Success(); } Random r = new Random(); List results = new List(); - foreach (ContractResponse contract in contracts) - { + foreach (ContractResponse contract in contracts) { if (config.ContractNames.Contains(contract.Description) == false) continue; @@ -183,44 +173,58 @@ public static async Task GenerateTransactions(ITransactionDataGeneratorS // Generate and send some sales Result saleResult = await t.SendSales(transactionDate, merchant, contract, numberOfSales, cancellationToken); - if (saleResult.IsFailed) - { + if (saleResult.IsFailed) { results.Add(contract.OperatorName); } } - if (results.Any()) - { + if (results.Any()) { return Result.Failure($"Error sending sales files for merchant [{merchant.MerchantName}] [{string.Join(",", results)}]"); } + return Result.Success(); } - public static async Task PerformSettlement(ITransactionDataGeneratorService t, DateTime dateTime, SettlementJobConfig config, CancellationToken cancellationToken) - { + public static async Task PerformSettlement(ITransactionDataGeneratorService t, + DateTime dateTime, + SettlementJobConfig config, + CancellationToken cancellationToken) { Result result = await t.PerformSettlement(dateTime.Date, config.EstateId, cancellationToken); - if (result.IsFailed) - { + if (result.IsFailed) { return Result.Failure($"Error performing settlement for Estate Id [{config.EstateId}] and date [{dateTime:dd-MM-yyyy}]"); } + return Result.Success(); } - public static async Task ReplayParkedQueues(ReplayParkedQueueJobConfig config, CancellationToken cancellationToken) - { - EventStoreClientSettings clientSettings = EventStoreClientSettings.Create(config.EventStoreAddress); - EventStorePersistentSubscriptionsClient client = new EventStorePersistentSubscriptionsClient(clientSettings); + public static async Task ReplayParkedQueues(ReplayParkedQueueJobConfig config, + CancellationToken cancellationToken) { + try { + EventStoreClientSettings clientSettings = EventStoreClientSettings.Create(config.EventStoreAddress); + EventStorePersistentSubscriptionsClient client = new EventStorePersistentSubscriptionsClient(clientSettings); - IEnumerable subscriptions = await client.ListAllAsync(cancellationToken: cancellationToken); + IEnumerable subscriptions = await client.ListAllAsync(cancellationToken: cancellationToken); - foreach (PersistentSubscriptionInfo persistentSubscriptionInfo in subscriptions) - { - if (persistentSubscriptionInfo.Stats.ParkedMessageCount > 0) - { - await client.ReplayParkedMessagesToStreamAsync(persistentSubscriptionInfo.EventSource, - persistentSubscriptionInfo.GroupName, cancellationToken: cancellationToken); + if (subscriptions.Any() == false) { + return Result.Success("No subscriptions found to replay parked messages."); } + + foreach (PersistentSubscriptionInfo persistentSubscriptionInfo in subscriptions) { + Logger.LogInformation($"About to process subscription [{persistentSubscriptionInfo.GroupName}] on stream [{persistentSubscriptionInfo.EventSource}]"); + if (persistentSubscriptionInfo.Stats.ParkedMessageCount > 0) { + Logger.LogWarning($"[{persistentSubscriptionInfo.Stats.ParkedMessageCount}] parked messages to be replayed."); + await client.ReplayParkedMessagesToStreamAsync(persistentSubscriptionInfo.EventSource, persistentSubscriptionInfo.GroupName, cancellationToken: cancellationToken); + Logger.LogWarning($"{persistentSubscriptionInfo.Stats.ParkedMessageCount} Parked messages replayed for subscription [{persistentSubscriptionInfo.GroupName}] on stream [{persistentSubscriptionInfo.EventSource}]."); + } + else { + Logger.LogWarning($"{persistentSubscriptionInfo.Stats.ParkedMessageCount} Parked messages replayed for subscription [{persistentSubscriptionInfo.GroupName}] on stream [{persistentSubscriptionInfo.EventSource}]."); + } + } + return Result.Success("Parked messages replayed successfully."); + } + catch (Exception ex) { + return Result.Failure($"Error replaying parked messages: {ex.Message}"); } } -} \ No newline at end of file +} diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/MakeFloatCreditsJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/MakeFloatCreditsJob.cs index 401f674..4e70788 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/MakeFloatCreditsJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/MakeFloatCreditsJob.cs @@ -1,5 +1,6 @@ -using System.Threading.Tasks; -using Quartz; +using Quartz; +using SimpleResults; +using System.Threading.Tasks; using TransactionProcessing.SchedulerService.DataGenerator; using TransactionProcessing.SchedulerService.Jobs.Common; using TransactionProcessing.SchedulerService.Jobs.Configuration; @@ -7,14 +8,12 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs; public class MakeFloatCredits : BaseJob { - public override async Task ExecuteJob(IJobExecutionContext context) { + public override async Task ExecuteJob(IJobExecutionContext context) { MakeFloatCreditsJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); ITransactionDataGeneratorService t = this.CreateTransactionDataGenerator(configuration.ClientId, configuration.ClientSecret, RunningMode.Live); t.TraceGenerated += this.TraceGenerated; - var result = await Jobs.GenerateFloatCredits(t, configuration, context.CancellationToken); - if (result.IsFailed) - throw new JobExecutionException(result.Message); + return await Jobs.GenerateFloatCredits(t, configuration, context.CancellationToken); } } \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ProcessSettlementJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ProcessSettlementJob.cs index bce5c81..eae36a2 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ProcessSettlementJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ProcessSettlementJob.cs @@ -7,19 +7,17 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs { using Quartz; using Shared.Logger; + using SimpleResults; using TransactionProcessing.SchedulerService.DataGenerator; public class ProcessSettlementJob : BaseJob { - public override async Task ExecuteJob(IJobExecutionContext context) - { + public override async Task ExecuteJob(IJobExecutionContext context) { SettlementJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); ITransactionDataGeneratorService t = CreateTransactionDataGenerator(configuration.ClientId, configuration.ClientSecret, RunningMode.Live); t.TraceGenerated += TraceGenerated; - var result = await Jobs.PerformSettlement(t, DateTime.Now, configuration, context.CancellationToken); - if (result.IsFailed) - throw new JobExecutionException(result.Message); + return await Jobs.PerformSettlement(t, DateTime.Now, configuration, context.CancellationToken); } } } diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ReplayParkedQueuesJob.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ReplayParkedQueuesJob.cs index 15c2040..d4d16d6 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ReplayParkedQueuesJob.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.Jobs/Jobs/ReplayParkedQueuesJob.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Quartz; +using SimpleResults; using TransactionProcessing.SchedulerService.Jobs.Common; using TransactionProcessing.SchedulerService.Jobs.Configuration; @@ -7,10 +8,10 @@ namespace TransactionProcessing.SchedulerService.Jobs.Jobs; public class ReplayParkedQueuesJob : BaseJob { - public override async Task ExecuteJob(IJobExecutionContext context) + public override async Task ExecuteJob(IJobExecutionContext context) { ReplayParkedQueueJobConfig configuration = Helpers.LoadJobConfig(context.MergedJobDataMap); - await Jobs.ReplayParkedQueues(configuration, context.CancellationToken); + return await Jobs.ReplayParkedQueues(configuration, context.CancellationToken); } } \ No newline at end of file diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs index 2c6b66d..cea938b 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/Startup.cs @@ -12,12 +12,16 @@ namespace TransactionProcessing.SchedulerService using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; + using NLog; + using NLog.Config; using NLog.Extensions.Logging; using Quartz; using Quartz.Impl; using Quartz.Impl.AdoJobStore.Common; using Quartz.Impl.Matchers; using Quartz.Spi; + using Shared.Extensions; + using Shared.General; using Shared.Logger; using SilkierQuartz; using System; @@ -67,23 +71,43 @@ public Startup(IWebHostEnvironment webHostEnvironment){ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { + ConfigurationReader.Initialise(Startup.Configuration); String nlogConfigFilename = "nlog.config"; - - if (env.IsDevelopment()){ + + if (env.IsDevelopment()) + { app.UseDeveloperExceptionPage(); + + string directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + LogManager.AddHiddenAssembly(Assembly.LoadFrom(Path.Combine(directoryPath, "Shared.dll"))); + + var developmentNlogConfigFilename = "nlog.development.config"; + var developmentConfigPath = Path.Combine(env.ContentRootPath, developmentNlogConfigFilename); + + if (File.Exists(developmentConfigPath)) + { + nlogConfigFilename = developmentNlogConfigFilename; + } } - else{ - app.UseExceptionHandler("/Error"); + else + { + LogManager.AddHiddenAssembly(Assembly.LoadFrom(Path.Combine(env.ContentRootPath, "Shared.dll"))); } - - loggerFactory.ConfigureNLog(Path.Combine(env.ContentRootPath, nlogConfigFilename)); + string configPath = Path.Combine(env.ContentRootPath, nlogConfigFilename); + + // Correct way to load config with auto-reload support + LogManager.Configuration = new XmlLoggingConfiguration(configPath); + + // Register NLog with ILoggerFactory loggerFactory.AddNLog(); - - ILogger logger = loggerFactory.CreateLogger("EstateManagement"); - Logger.Initialise(logger); + ILogger logger = loggerFactory.CreateLogger("TransactionProcessor"); + + Shared.Logger.Logger.Initialise(logger); + + Startup.Configuration.LogConfiguration(Shared.Logger.Logger.LogWarning); app.UseStaticFiles(); app.UseRouting(); @@ -140,14 +164,11 @@ private void RegisterJobs(IServiceCollection services) public class CustomSqlServerConnectionProvider : IDbProvider { - private readonly ILogger logger; + //private readonly ILogger logger; private readonly IConfiguration configuration; - public CustomSqlServerConnectionProvider( - ILogger logger, - IConfiguration configuration) + public CustomSqlServerConnectionProvider(IConfiguration configuration) { - this.logger = logger; this.configuration = configuration; Metadata = new DbMetadata { @@ -168,7 +189,7 @@ public CustomSqlServerConnectionProvider( public void Initialize() { - logger.LogInformation("Initializing"); + Shared.Logger.Logger.LogInformation("Initializing"); } public DbCommand CreateCommand() @@ -191,7 +212,7 @@ public string ConnectionString public void Shutdown() { - logger.LogInformation("Shutting down"); + Shared.Logger.Logger.LogInformation("Shutting down"); } } @@ -226,7 +247,7 @@ public static IServiceCollection AddScheduler(this IServiceCollection services, // we take this from appsettings.json, just show it's possible q.SchedulerName = "Txn Processing Scheduler"; - + // these are the defaults q.UseSimpleTypeLoader(); q.UsePersistentStore(s => { @@ -248,7 +269,7 @@ public static IServiceCollection AddScheduler(this IServiceCollection services, ExecutionHistoryPlugin p = new ExecutionHistoryPlugin(); p.StoreType = Type.GetType("Quartz.Plugins.RecentHistory.Impl.InProcExecutionHistoryStore,Quartz.Plugins.RecentHistory"); p.Name = "ExecutionHistoryPlugin"; - q.AddJobListener(p); + //q.AddJobListener(p); }); return services; diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.csproj b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.csproj index af14cf7..fb7bed9 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.csproj +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService.csproj @@ -22,6 +22,9 @@ + + Always + Always diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json index 64ab144..fa94969 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/appsettings.json @@ -1,4 +1,11 @@ { + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.AspNetCore": "Warning" + } + }, "ConnectionStrings": { "Quartz": "server=127.0.0.1;user id=sa;password=Sc0tland;database=Scheduler;Encrypt=True;TrustServerCertificate=True" }, diff --git a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/nlog.config b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/nlog.config index b58ae4e..511577f 100644 --- a/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/nlog.config +++ b/TransactionProcessing.SchedulerService/TransactionProcessing.SchedulerService/nlog.config @@ -1,5 +1,6 @@  - + + + - - + +