Migrate MaintenanceService, IngestEvents processing, UpdateAdminConfig to DAL

- MaintenanceService → IMaintenanceRepository + ISessionRepository + IMetricsRepository
- IngestEventsFunction.Processing → updated repository references
- UpdateAdminConfigurationFunction → IMaintenanceRepository

https://claude.ai/code/session_01NHWJfPaa8TQHuPzMD7gG63
This commit is contained in:
Claude
2026-03-27 06:32:37 +00:00
parent 7bf139ecbe
commit bd41ea05c7
3 changed files with 19 additions and 13 deletions
@@ -18,16 +18,16 @@ namespace AutopilotMonitor.Functions.Functions.Config
{
private readonly ILogger<UpdateAdminConfigurationFunction> _logger;
private readonly AdminConfigurationService _adminConfigService;
private readonly TableStorageService _storageService;
private readonly IMaintenanceRepository _maintenanceRepo;
public UpdateAdminConfigurationFunction(
ILogger<UpdateAdminConfigurationFunction> logger,
AdminConfigurationService adminConfigService,
TableStorageService storageService)
IMaintenanceRepository maintenanceRepo)
{
_logger = logger;
_adminConfigService = adminConfigService;
_storageService = storageService;
_maintenanceRepo = maintenanceRepo;
}
[Function("UpdateAdminConfiguration")]
@@ -175,7 +175,7 @@ namespace AutopilotMonitor.Functions.Functions.Ingest
var geoData = classification.DeviceLocationEvent.Data;
var geoTenantId = request.TenantId;
var geoSessionId = request.SessionId;
_ = _storageService.UpdateSessionGeoAsync(
_ = _sessionRepo.UpdateSessionGeoAsync(
geoTenantId,
geoSessionId,
geoData.ContainsKey("country") ? geoData["country"]?.ToString() : null,
@@ -193,7 +193,7 @@ namespace AutopilotMonitor.Functions.Functions.Ingest
// Always increment event count when events were stored
if (processedCount > 0)
{
await _storageService.IncrementSessionEventCountAsync(
await _sessionRepo.IncrementSessionEventCountAsync(
request.TenantId,
request.SessionId,
processedCount,
@@ -217,12 +217,12 @@ namespace AutopilotMonitor.Functions.Functions.Ingest
{
try
{
var ruleEngine = new RuleEngine(_analyzeRuleService, _storageService, _logger);
var ruleEngine = new RuleEngine(_analyzeRuleService, _ruleRepo, _sessionRepo, _logger);
var results = await ruleEngine.AnalyzeSessionAsync(ruleTenantId, ruleSessionId);
foreach (var result in results)
{
await _storageService.StoreRuleResultAsync(result);
await _ruleRepo.StoreRuleResultAsync(result);
}
if (results.Count > 0)
@@ -238,7 +238,7 @@ namespace AutopilotMonitor.Functions.Functions.Ingest
// Increment platform stats for detected issues
if (results.Count > 0)
{
_ = _storageService.IncrementPlatformStatAsync("IssuesDetected", results.Count)
_ = _metricsRepo.IncrementPlatformStatAsync("IssuesDetected", results.Count)
.ContinueWith(t => _logger.LogWarning(t.Exception?.InnerException,
"Fire-and-forget IncrementPlatformStatAsync failed"), TaskContinuationOptions.OnlyOnFaulted);
}
@@ -41,7 +41,9 @@ namespace AutopilotMonitor.Functions.Services
/// </summary>
public partial class MaintenanceService
{
private readonly TableStorageService _storageService;
private readonly IMaintenanceRepository _maintenanceRepo;
private readonly ISessionRepository _sessionRepo;
private readonly IMetricsRepository _metricsRepo;
private readonly TenantConfigurationService _tenantConfigService;
private readonly UsageMetricsService _usageMetricsService;
private readonly AdminConfigurationService _adminConfigurationService;
@@ -54,7 +56,9 @@ namespace AutopilotMonitor.Functions.Services
private const string PlatformStatsVersionedCacheControl = "public, max-age=31536000, immutable";
public MaintenanceService(
TableStorageService storageService,
IMaintenanceRepository maintenanceRepo,
ISessionRepository sessionRepo,
IMetricsRepository metricsRepo,
TenantConfigurationService tenantConfigService,
UsageMetricsService usageMetricsService,
AdminConfigurationService adminConfigurationService,
@@ -62,7 +66,9 @@ namespace AutopilotMonitor.Functions.Services
TenantAdminsService tenantAdminsService,
ILogger<MaintenanceService> logger)
{
_storageService = storageService;
_maintenanceRepo = maintenanceRepo;
_sessionRepo = sessionRepo;
_metricsRepo = metricsRepo;
_tenantConfigService = tenantConfigService;
_usageMetricsService = usageMetricsService;
_adminConfigurationService = adminConfigurationService;
@@ -175,7 +181,7 @@ namespace AutopilotMonitor.Functions.Services
try
{
var tenantIds = await _storageService.GetAllTenantIdsAsync();
var tenantIds = await _maintenanceRepo.GetAllTenantIdsAsync();
int totalSessionsTimedOut = 0;
foreach (var tenantId in tenantIds)
@@ -261,7 +267,7 @@ namespace AutopilotMonitor.Functions.Services
var windowCutoff = DateTime.UtcNow.AddHours(-adminConfig.MaxSessionWindowHours);
var blockDurationHours = adminConfig.MaintenanceBlockDurationHours;
var tenantIds = await _storageService.GetAllTenantIdsAsync();
var tenantIds = await _maintenanceRepo.GetAllTenantIdsAsync();
int totalBlocked = 0;
foreach (var tenantId in tenantIds)