From f75524f85d7a36217c0c022a271040f2bd9dd9e8 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 4 Aug 2026 16:33:26 +0200 Subject: [PATCH] feat(config): add DexJobOptions configuration system and update placeholder pattern - Add SectionName constant to DexJobOptions - Update placeholder pattern to {#INT#BATCH_ID} - Add DexJob configuration section to appsettings.json - Add IConfiguration parameter to DependencyInjection for options binding - Add Microsoft.Extensions.Options.ConfigurationExtensions package for .NET Framework 4.8 - Improve code documentation and move class into namespace --- .../Common/Options/DexJobOptions.cs | 152 +++++++++--------- .../DependencyInjection.cs | 8 +- .../ECMJobRunner.Application.csproj | 4 +- ECMJobRunner.WebCron/appsettings.json | 23 +++ 4 files changed, 111 insertions(+), 76 deletions(-) diff --git a/ECMJobRunner.Application/Common/Options/DexJobOptions.cs b/ECMJobRunner.Application/Common/Options/DexJobOptions.cs index 988fc65..44d0555 100644 --- a/ECMJobRunner.Application/Common/Options/DexJobOptions.cs +++ b/ECMJobRunner.Application/Common/Options/DexJobOptions.cs @@ -1,105 +1,109 @@ using ECMJobRunner.Application.Common.Constants; using System.Text.RegularExpressions; -namespace ECMJobRunner.Application.Common.Options +namespace ECMJobRunner.Application.Common.Options; + +/// +/// Configuration options for DEX job execution +/// +public class DexJobOptions { /// - /// Configuration options for DEX job execution + /// The configuration section name used to bind this options class from application settings /// - public class DexJobOptions + public const string SectionName = "DexJob"; + + /// + /// Error handling options for DEX job operations + /// + public record DexJobErrorHandlingOptions { /// - /// Error handling options for DEX job operations + /// Error handling options for SQL query execution /// - public record DexJobErrorHandlingOptions + public record SqlQueryErrorHandlingOptions { /// - /// Error handling options for SQL query execution + /// Action to take when query execution fails /// - public record SqlQueryErrorHandlingOptions - { - /// - /// Action to take when query execution fails - /// - public ErrorAction OnExecution { get; set; } = ErrorAction.Stop; - - /// - /// Action to take when query is null or whitespace - /// - public ErrorAction IfNullOrWhiteSpace { get; set; } = ErrorAction.Ignore; - - /// - /// Action to take when query returns unexpected result - /// - public ErrorAction OnUnexpectedResult { get; set; } = ErrorAction.Stop; - } + public ErrorAction OnExecution { get; set; } = ErrorAction.Stop; /// - /// Error handling options for HTTP requests + /// Action to take when query is null or whitespace /// - public record HttpRequestErrorHandlingOptions - { - /// - /// Action to take when HTTP request fails - /// - public ErrorAction OnSending { get; set; } = ErrorAction.Stop; - } + public ErrorAction IfNullOrWhiteSpace { get; set; } = ErrorAction.Ignore; /// - /// Error handling for main SQL query + /// Action to take when query returns unexpected result /// - public SqlQueryErrorHandlingOptions MainQuery { get; set; } = new(); - - /// - /// Error handling for check SQL query - /// - public SqlQueryErrorHandlingOptions CheckQuery { get; set; } = new(); - - /// - /// Error handling for ReC HTTP request - /// - public HttpRequestErrorHandlingOptions ReCRequest { get; set; } = new(); + public ErrorAction OnUnexpectedResult { get; set; } = ErrorAction.Stop; } /// - /// Error handling configuration + /// Error handling options for HTTP requests /// - public DexJobErrorHandlingOptions Error { get; set; } = new(); - - /// - /// Placeholder configuration for dynamic value replacement - /// - public record PlaceHolderOptions + public record HttpRequestErrorHandlingOptions { /// - /// Configuration for a single placeholder + /// Action to take when HTTP request fails /// - public record PlaceHolder - { - /// - /// Regex pattern to match the placeholder - /// - public string Pattern { get; set; } = null!; - - /// - /// Regex options for pattern matching - /// - public RegexOptions RegexOptions { get; set; } = RegexOptions.IgnoreCase; - } - - /// - /// BatchId placeholder configuration - /// - public PlaceHolder BatchId { get; set; } = new() - { - Pattern = "#INT#BATCH_ID", - RegexOptions = RegexOptions.IgnoreCase - }; + public ErrorAction OnSending { get; set; } = ErrorAction.Stop; } /// - /// Placeholder configuration + /// Error handling for main SQL query /// - public PlaceHolderOptions Placeholders { get; set; } = new(); + public SqlQueryErrorHandlingOptions MainQuery { get; set; } = new(); + + /// + /// Error handling for check SQL query + /// + public SqlQueryErrorHandlingOptions CheckQuery { get; set; } = new(); + + /// + /// Error handling for ReC HTTP request + /// + public HttpRequestErrorHandlingOptions ReCRequest { get; set; } = new(); } + + /// + /// Error handling configuration + /// + public DexJobErrorHandlingOptions Error { get; set; } = new(); + + /// + /// Placeholder configuration for dynamic value replacement + /// + public record PlaceHolderOptions + { + /// + /// Configuration for a single placeholder + /// + public record PlaceHolder + { + /// + /// Regex pattern to match the placeholder + /// + public string Pattern { get; set; } = null!; + + /// + /// Regex options for pattern matching + /// + public RegexOptions RegexOptions { get; set; } = RegexOptions.IgnoreCase; + } + + /// + /// BatchId placeholder configuration + /// + public PlaceHolder BatchId { get; set; } = new() + { + Pattern = "{#INT#BATCH_ID}", + RegexOptions = RegexOptions.IgnoreCase + }; + } + + /// + /// Placeholder configuration + /// + public PlaceHolderOptions Placeholders { get; set; } = new(); } diff --git a/ECMJobRunner.Application/DependencyInjection.cs b/ECMJobRunner.Application/DependencyInjection.cs index 857f187..f6c302c 100644 --- a/ECMJobRunner.Application/DependencyInjection.cs +++ b/ECMJobRunner.Application/DependencyInjection.cs @@ -1,5 +1,7 @@ +using ECMJobRunner.Application.Common.Options; using ECMJobRunner.Application.Profiles.Commands.Behaviors; using MediatR; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using ReC.Client; using System.Reflection; @@ -17,8 +19,9 @@ namespace ECMJobRunner.Application /// /// The service collection /// The base URL for the ReC client API + /// The application configuration /// The service collection for chaining - public static IServiceCollection AddJobRunnerServices(this IServiceCollection services, string recClientApiUrl) + public static IServiceCollection AddJobRunnerServices(this IServiceCollection services, string recClientApiUrl, IConfiguration configuration) { var assembly = Assembly.GetExecutingAssembly(); @@ -36,6 +39,9 @@ namespace ECMJobRunner.Application opt.LogSuccessfulRequests = true; }); + // Configure DexJobOptions from appsettings.json + services.Configure(configuration.GetSection(DexJobOptions.SectionName)); + // Register pipeline behaviors in execution order // Order matters: MainQuery -> CheckQuery -> ReCRequest services.AddTransient(typeof(IPipelineBehavior<,>), typeof(JobExceptionHandlingBehavior<,>)); diff --git a/ECMJobRunner.Application/ECMJobRunner.Application.csproj b/ECMJobRunner.Application/ECMJobRunner.Application.csproj index 544e80d..34c75c2 100644 --- a/ECMJobRunner.Application/ECMJobRunner.Application.csproj +++ b/ECMJobRunner.Application/ECMJobRunner.Application.csproj @@ -17,7 +17,7 @@ - + @@ -31,6 +31,8 @@ + + diff --git a/ECMJobRunner.WebCron/appsettings.json b/ECMJobRunner.WebCron/appsettings.json index 4bc43f8..02c5a43 100644 --- a/ECMJobRunner.WebCron/appsettings.json +++ b/ECMJobRunner.WebCron/appsettings.json @@ -23,5 +23,28 @@ }, "ProfileWorker": { "IntervalMS": 60000 + }, + "DexJob": { + "Error": { + "MainQuery": { + "OnExecution": "Stop", + "IfNullOrWhiteSpace": "Ignore", + "OnUnexpectedResult": "Stop" + }, + "CheckQuery": { + "OnExecution": "Stop", + "IfNullOrWhiteSpace": "Ignore", + "OnUnexpectedResult": "Stop" + }, + "ReCRequest": { + "OnSending": "Stop" + } + }, + "Placeholders": { + "BatchId": { + "Pattern": "{#INT#BATCH_ID}", + "RegexOptions": "IgnoreCase" + } + } } }