refactor(dotnet): externalize scheduler definitions
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Reflection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.Common;
|
using Hangfire.Common;
|
||||||
using QuantEngine.Web.Services;
|
using QuantEngine.Web.Services;
|
||||||
@@ -33,7 +34,8 @@ public class SchedulerServiceTests
|
|||||||
recurringJobManagerMock.Object,
|
recurringJobManagerMock.Object,
|
||||||
scopeFactoryMock.Object,
|
scopeFactoryMock.Object,
|
||||||
configMock.Object,
|
configMock.Object,
|
||||||
parser
|
parser,
|
||||||
|
Options.Create(new SchedulerServiceOptions())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -198,7 +200,8 @@ public class SchedulerServiceTests
|
|||||||
recurringJobManagerMock.Object,
|
recurringJobManagerMock.Object,
|
||||||
scopeFactoryMock.Object,
|
scopeFactoryMock.Object,
|
||||||
configMock.Object,
|
configMock.Object,
|
||||||
new GatherTradingDataParser()
|
new GatherTradingDataParser(),
|
||||||
|
Options.Create(new SchedulerServiceOptions())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ try
|
|||||||
builder.Services.AddScoped<PriceDataNormalizer>();
|
builder.Services.AddScoped<PriceDataNormalizer>();
|
||||||
builder.Services.AddScoped<ICollectionOrchestrator, KisDataCollectionOrchestrator>();
|
builder.Services.AddScoped<ICollectionOrchestrator, KisDataCollectionOrchestrator>();
|
||||||
builder.Services.AddScoped<IPriceHistoryReader, PriceHistoryReader>();
|
builder.Services.AddScoped<IPriceHistoryReader, PriceHistoryReader>();
|
||||||
|
builder.Services.AddOptions<SchedulerServiceOptions>();
|
||||||
|
|
||||||
// Hangfire Background Jobs
|
// Hangfire Background Jobs
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -8,6 +8,17 @@ public sealed record SchedulerJobDefinition(
|
|||||||
string Description,
|
string Description,
|
||||||
bool IsRecurring);
|
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(
|
public sealed record SchedulerJobExecutionAudit(
|
||||||
string JobId,
|
string JobId,
|
||||||
string RunId,
|
string RunId,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using QuantEngine.Application.Services;
|
|||||||
using QuantEngine.Application.Interfaces;
|
using QuantEngine.Application.Interfaces;
|
||||||
using QuantEngine.Infrastructure.Data;
|
using QuantEngine.Infrastructure.Data;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace QuantEngine.Web.Services;
|
namespace QuantEngine.Web.Services;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ public class SchedulerService
|
|||||||
private readonly IServiceScopeFactory _scopeFactory;
|
private readonly IServiceScopeFactory _scopeFactory;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly GatherTradingDataParser _parser;
|
private readonly GatherTradingDataParser _parser;
|
||||||
|
private readonly SchedulerServiceOptions _options;
|
||||||
private readonly string _auditRoot;
|
private readonly string _auditRoot;
|
||||||
|
|
||||||
public SchedulerService(
|
public SchedulerService(
|
||||||
@@ -31,7 +33,8 @@ public class SchedulerService
|
|||||||
IRecurringJobManager recurringJobManager,
|
IRecurringJobManager recurringJobManager,
|
||||||
IServiceScopeFactory scopeFactory,
|
IServiceScopeFactory scopeFactory,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
GatherTradingDataParser parser)
|
GatherTradingDataParser parser,
|
||||||
|
IOptions<SchedulerServiceOptions> options)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_jobClient = jobClient;
|
_jobClient = jobClient;
|
||||||
@@ -39,6 +42,7 @@ public class SchedulerService
|
|||||||
_scopeFactory = scopeFactory;
|
_scopeFactory = scopeFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_parser = parser;
|
_parser = parser;
|
||||||
|
_options = options.Value ?? new SchedulerServiceOptions();
|
||||||
_auditRoot = FindRepoTempRoot();
|
_auditRoot = FindRepoTempRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,13 +131,8 @@ public class SchedulerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<SchedulerJobDefinition> GetRecurringJobDefinitions() => new[]
|
public IReadOnlyList<SchedulerJobDefinition> GetRecurringJobDefinitions()
|
||||||
{
|
=> _options.JobDefinitions.Count > 0 ? _options.JobDefinitions : new SchedulerServiceOptions().JobDefinitions;
|
||||||
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),
|
|
||||||
};
|
|
||||||
|
|
||||||
private static string? FindGatherTradingDataJson()
|
private static string? FindGatherTradingDataJson()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user