From c852ad49cf93daa537bc09972bf634a044b1d665 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Mon, 13 Jul 2026 00:39:59 +0900 Subject: [PATCH] refactor(dotnet): externalize scheduler definitions --- .../SchedulerServiceTests.cs | 7 +++++-- src/dotnet/QuantEngine.Web/Program.cs | 1 + .../QuantEngine.Web/Services/SchedulerModels.cs | 11 +++++++++++ .../QuantEngine.Web/Services/SchedulerService.cs | 15 +++++++-------- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/dotnet/QuantEngine.Core.Tests/SchedulerServiceTests.cs b/src/dotnet/QuantEngine.Core.Tests/SchedulerServiceTests.cs index 9477e763..091392ad 100644 --- a/src/dotnet/QuantEngine.Core.Tests/SchedulerServiceTests.cs +++ b/src/dotnet/QuantEngine.Core.Tests/SchedulerServiceTests.cs @@ -4,6 +4,7 @@ using System.Reflection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Hangfire; using Hangfire.Common; using QuantEngine.Web.Services; @@ -33,7 +34,8 @@ public class SchedulerServiceTests recurringJobManagerMock.Object, scopeFactoryMock.Object, configMock.Object, - parser + parser, + Options.Create(new SchedulerServiceOptions()) ); // Act @@ -198,7 +200,8 @@ public class SchedulerServiceTests recurringJobManagerMock.Object, scopeFactoryMock.Object, configMock.Object, - new GatherTradingDataParser() + new GatherTradingDataParser(), + Options.Create(new SchedulerServiceOptions()) ); } diff --git a/src/dotnet/QuantEngine.Web/Program.cs b/src/dotnet/QuantEngine.Web/Program.cs index b1d43a46..c3aa764d 100644 --- a/src/dotnet/QuantEngine.Web/Program.cs +++ b/src/dotnet/QuantEngine.Web/Program.cs @@ -116,6 +116,7 @@ try builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + builder.Services.AddOptions(); // Hangfire Background Jobs try diff --git a/src/dotnet/QuantEngine.Web/Services/SchedulerModels.cs b/src/dotnet/QuantEngine.Web/Services/SchedulerModels.cs index c7ac2004..6b8435a2 100644 --- a/src/dotnet/QuantEngine.Web/Services/SchedulerModels.cs +++ b/src/dotnet/QuantEngine.Web/Services/SchedulerModels.cs @@ -8,6 +8,17 @@ public sealed record SchedulerJobDefinition( string Description, bool IsRecurring); +public sealed record SchedulerServiceOptions +{ + public List JobDefinitions { get; init; } = new() + { + new SchedulerJobDefinition("daily-collection", "0 9 * * *", "Daily data collection", true), + new SchedulerJobDefinition("hourly-price-update", "0 9,11,13,15 * * 1-5", "Hourly price update", true), + new SchedulerJobDefinition("weekly-report", "0 17 * * 5", "Weekly report generation", true), + new SchedulerJobDefinition("monthly-optimization", "0 2 1 * *", "Monthly optimization", true), + }; +} + public sealed record SchedulerJobExecutionAudit( string JobId, string RunId, diff --git a/src/dotnet/QuantEngine.Web/Services/SchedulerService.cs b/src/dotnet/QuantEngine.Web/Services/SchedulerService.cs index 0d2ab612..cc074e0f 100644 --- a/src/dotnet/QuantEngine.Web/Services/SchedulerService.cs +++ b/src/dotnet/QuantEngine.Web/Services/SchedulerService.cs @@ -9,6 +9,7 @@ using QuantEngine.Application.Services; using QuantEngine.Application.Interfaces; using QuantEngine.Infrastructure.Data; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; namespace QuantEngine.Web.Services; @@ -23,6 +24,7 @@ public class SchedulerService private readonly IServiceScopeFactory _scopeFactory; private readonly IConfiguration _configuration; private readonly GatherTradingDataParser _parser; + private readonly SchedulerServiceOptions _options; private readonly string _auditRoot; public SchedulerService( @@ -31,7 +33,8 @@ public class SchedulerService IRecurringJobManager recurringJobManager, IServiceScopeFactory scopeFactory, IConfiguration configuration, - GatherTradingDataParser parser) + GatherTradingDataParser parser, + IOptions options) { _logger = logger; _jobClient = jobClient; @@ -39,6 +42,7 @@ public class SchedulerService _scopeFactory = scopeFactory; _configuration = configuration; _parser = parser; + _options = options.Value ?? new SchedulerServiceOptions(); _auditRoot = FindRepoTempRoot(); } @@ -127,13 +131,8 @@ public class SchedulerService } } - public IReadOnlyList GetRecurringJobDefinitions() => new[] - { - new SchedulerJobDefinition("daily-collection", "0 9 * * *", "Daily data collection", true), - new SchedulerJobDefinition("hourly-price-update", "0 9,11,13,15 * * 1-5", "Hourly price update", true), - new SchedulerJobDefinition("weekly-report", "0 17 * * 5", "Weekly report generation", true), - new SchedulerJobDefinition("monthly-optimization", "0 2 1 * *", "Monthly optimization", true), - }; + public IReadOnlyList GetRecurringJobDefinitions() + => _options.JobDefinitions.Count > 0 ? _options.JobDefinitions : new SchedulerServiceOptions().JobDefinitions; private static string? FindGatherTradingDataJson() {