fix(architecture): abstract job run state access

This commit is contained in:
Alexandre Brandizzi 2026-07-24 16:40:46 -03:00
parent 638eccd46c
commit df291ea9a6
3 changed files with 19 additions and 10 deletions

View file

@ -13,6 +13,7 @@ using System.Text;
using SeaHaven.DataServices.DependencyInjection;
using SeaHaven.Services.DependencyInjection;
using SeaHaven.Services.Implementation;
using SeaHaven.Services.Interfaces;
var builder = WebApplication.CreateBuilder(args);
ConfigurationManager configuration = builder.Configuration;
@ -83,6 +84,8 @@ builder.Services.Configure<SyncOptions>(
builder.Services.Configure<LegacyEndpointOptions>(
builder.Configuration.GetSection(LegacyEndpointOptions.SectionName));
builder.Services.AddSingleton<WorkOrderJobRunStateAccessor>();
builder.Services.AddSingleton<IWorkOrderJobRunStateAccessor>(
sp => sp.GetRequiredService<WorkOrderJobRunStateAccessor>());
builder.Services.AddSingleton(sp => sp.GetRequiredService<WorkOrderJobRunStateAccessor>().State);
builder.Services.AddScoped<Api.SeaHavenIndustries.Filters.IngestApiKeyFilter>();
builder.Services.AddHostedService<WorkOrderWeekRolledHostedService>();

View file

@ -8,12 +8,12 @@ namespace SeaHaven.Services.Implementation
public class WorkOrderOpsHealthService : IWorkOrderOpsHealthService
{
private readonly IWorkOrderOpsHealthDataService _healthData;
private readonly WorkOrderJobRunStateAccessor _runState;
private readonly IWorkOrderJobRunStateAccessor _runState;
private readonly WorkOrderOpsHealthOptions _options;
public WorkOrderOpsHealthService(
IWorkOrderOpsHealthDataService healthData,
WorkOrderJobRunStateAccessor runState,
IWorkOrderJobRunStateAccessor runState,
IOptions<WorkOrderOpsHealthOptions> options)
{
_healthData = healthData;
@ -58,16 +58,9 @@ namespace SeaHaven.Services.Implementation
}
/// <summary>Shared in-memory job run timestamps (API hosted services + ops health).</summary>
public class WorkOrderJobRunStateAccessor
public class WorkOrderJobRunStateAccessor : IWorkOrderJobRunStateAccessor
{
public WorkOrderJobRunState State { get; } = new();
}
public class WorkOrderJobRunState
{
public DateTime? LastWeekRolledRunUtc { get; set; }
public DateTime? LastPastDueCacheRunUtc { get; set; }
public string? LastWeekRolledError { get; set; }
public string? LastPastDueCacheError { get; set; }
}
}

View file

@ -2,6 +2,19 @@ using Microsoft.AspNetCore.Http;
namespace SeaHaven.Services.Interfaces
{
public interface IWorkOrderJobRunStateAccessor
{
WorkOrderJobRunState State { get; }
}
public sealed class WorkOrderJobRunState
{
public DateTime? LastWeekRolledRunUtc { get; set; }
public DateTime? LastPastDueCacheRunUtc { get; set; }
public string? LastWeekRolledError { get; set; }
public string? LastPastDueCacheError { get; set; }
}
public interface IFileStoragePort
{
Task<string> SaveFileAsync(IFormFile file);