Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Functions/Admin/MaintenanceFunction.cs
T
Oliver Kieselbach e5f955354d Hourly SessionSweep interleave: stalled-session sweep every hour instead of 2h
New SessionSweepFunction (cron 0 30 * * * *, offset from the 2h Maintenance
timer at minute 0) runs only MarkStalledSessionsAsTimedOutAsync, halving the
sweep-induced classification latency; thresholds unchanged. The sweep now
returns a SessionSweepResult (counts + catastrophic-failure message) so the
new timer emits SessionSweepCompleted heartbeats / SessionSweepFailed errors
(dual-registered in the ops-alert web catalog). No lease: the sweep is
idempotent, overlap with the 2h chain is a no-op.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 14:33:26 +02:00

41 lines
1.6 KiB
C#

using System.Threading.Tasks;
using AutopilotMonitor.Functions.Services;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace AutopilotMonitor.Functions.Functions.Admin
{
/// <summary>
/// Timer-triggered Azure Function that runs periodic maintenance.
/// Delegates all logic to MaintenanceService.
/// </summary>
public class MaintenanceFunction
{
private readonly MaintenanceService _maintenanceService;
private readonly ILogger<MaintenanceFunction> _logger;
public MaintenanceFunction(
MaintenanceService maintenanceService,
ILogger<MaintenanceFunction> logger)
{
_maintenanceService = maintenanceService;
_logger = logger;
}
/// <summary>
/// Timer trigger: Runs every 2 hours
/// NCRONTAB format: {second} {minute} {hour} {day} {month} {day-of-week}
/// Reduced from daily (2:00 UTC) to every 2 hours to catch stalled sessions faster.
/// MarkStalledSessionsAsTimedOutAsync is idempotent (terminal states not overwritten).
/// The stalled-session sweep additionally runs hourly at minute 30 via the dedicated
/// SessionSweepFunction interleave — this chain keeps it as its first step regardless.
/// </summary>
[Function("Maintenance")]
public async Task Run([TimerTrigger("0 0 */2 * * *")] object timer)
{
_logger.LogInformation("Maintenance timer trigger fired");
await _maintenanceService.RunAllAsync();
}
}
}