refactor(dotnet): externalize scheduler definitions
This commit is contained in:
@@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ try
|
||||
builder.Services.AddScoped<PriceDataNormalizer>();
|
||||
builder.Services.AddScoped<ICollectionOrchestrator, KisDataCollectionOrchestrator>();
|
||||
builder.Services.AddScoped<IPriceHistoryReader, PriceHistoryReader>();
|
||||
builder.Services.AddOptions<SchedulerServiceOptions>();
|
||||
|
||||
// Hangfire Background Jobs
|
||||
try
|
||||
|
||||
@@ -8,6 +8,17 @@ public sealed record SchedulerJobDefinition(
|
||||
string Description,
|
||||
bool IsRecurring);
|
||||
|
||||
public sealed record SchedulerServiceOptions
|
||||
{
|
||||
public List<SchedulerJobDefinition> 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,
|
||||
|
||||
@@ -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<SchedulerServiceOptions> 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<SchedulerJobDefinition> 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<SchedulerJobDefinition> GetRecurringJobDefinitions()
|
||||
=> _options.JobDefinitions.Count > 0 ? _options.JobDefinitions : new SchedulerServiceOptions().JobDefinitions;
|
||||
|
||||
private static string? FindGatherTradingDataJson()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user